codenijuan codenijuan - 4 months ago 9
jQuery Question

how to get the html tags only from a string using jquery

is it possible to get the HTML tag from a string with jQuery (or plain old JavaScript)?

example:

var htmltag = "<table><tr><td>sample text</td><td><input type="submit" value="Click"/></td></tr></table>";


the output must like this one

result:
<input type="submit" value="Click"/>


how i can get the html tag from a string using jquery?

Answer

You could use a regular expression to match what you want. In this case it might look like this:

htmltag.match("<input .*?>");

The result would be an array containing just the input tag.

Comments