codenijuan codenijuan - 1 year ago 89
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download