javascript - How to split string of HTML into pieces and strip outer tags? -
preferably jquery consistency context, pure js fine.
given string this, <li><img src="something.jpg"></li><li><img src="something2.jpg"></li>, how can convert this:
['<img src="something.jpg">', '<img src="something2.jpg">']
so want strip li tags away , array of images. know can split lis array, how can strip li tags off without doing hand?
check fiddle working demo: http://jsfiddle.net/smqdw/
// assuming "string" string, create ul in memory , // adding string build dom structure out of var $temp = $("<ul />").html(string); var images = []; // use jquery extract li elements dom structure , // append .html() result each array image strings. $temp.find("li").each(function() { images.push($(this).html()); });
Comments
Post a Comment