codenijuan codenijuan - 2 months ago 5x
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)?


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

the output must like this one

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

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


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.