how to find all <p> tags under one tag
I have code like this:
<p>Imnsxmn . jwbxhjwvxhvx"><a href="http://aaaaaa.com/" title="View all posts in " rel="category tag">MBA Business School</a> • </div>
<p>wjhdghw</p>
<h4><a href="http://list.com/" rel="bookmark" title="delhi ">code h开发者_如何学Celp</a> </h4>
<p>acavgcsgcsc sv sv</p>
.....
.......
.......
So what I want to is that I have to extract all p tags which comes under particular tag. I am curremtly using HTML dom library. Any help ?
Assuming that "under" means "inside" and not "after":
Use the getElementsByTagName method of the DOM node.
You need to do a loop
var p = document.getElementsByTagName("p");
for (var i=0;i<p.length;i++) {
... p[i] ...
}
How is what you need to do, using html dom library:
$html = new simple_html_dom();
$html->load("<p>Imnsxmn . jwbxhjwvxhvx"><a href='http://aaaaaa.com/' title='View all posts in ' rel='category tag'>MBA Business School</a> </div><p>wjhdghw</p><h4><a href='http://list.com/' rel='bookmark' title='delhi '>code help</a></h4><p>acavgcsgcsc sv sv</p>");
# get all p tags that are inside sometag
$collection = $html->find('sometag p');
I prefer you to use jquery.
$("#number p")
-> gives all ps' under id=number element.
$(".my p")
-> gives all ps' under the my class dom element
精彩评论