var x = '<p>blah</p><div><a href="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=brd&FlightID=2997227&Page=&PluID=0&Pos=9088" target="_blank"><img src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=2997227&Page=&PluID=0&Pos=9088" border=0 width=300 height=250></a></div>';
$(x).children('div').html();
Use the text method [text()
] to get text in the div element,
by identifing the element by class or id.
This is probably what you need:
$('div').html();
demo
This says get the div
and return all the contents inside it. See more here: http://api.jquery.com/html/
If you had many div
s on the page and needed to target just one, you could set an id
on the div
and call it like so
$('#whatever').html();
where whatever is the id
EDIT
Now that you have clarified your question re this being a string, here is a way to do it with vanilla js:
var l = x.length;
var y = x.indexOf('<div>');
var s = x.slice(y,l);
alert(s);
Demo Here
div
occursI suggest that you give an if to the div than:
$("#my_div_id").html();
Use the below where x is the variable which holds the markup in question.
$(x).find("div").html();
Give the div a class or id and do something like this:
$("#example").get().innerHTML;
That works at the DOM level.