开发者

how to find all <p> tags under one tag

开发者 https://www.devze.com 2023-03-11 12:37 出处:网络
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> &bull; </div&g

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> &bull; </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

0

精彩评论

暂无评论...
验证码 换一张
取 消