In my js I have a var in which I have stored innerHTML.
The var is having value something like
<h2>headline</h2>
<div>....</div>
...........
Now I want to retrieve value of h2 tag..what I am doing is
$(myvar).find("h2").text()
but its not working…what should be the exact syntax?
EDIT:
alert(myvar)=<h2>headline</h2>
<div>....</div>
Thanks.
The
findmethod will not work for this case, because it gets the descendants of each element in the current set of matched elements (theh2and thedivin your example).You can simply use
filter(available on jQuery 1.3.2):Check an example here.