开发者

Selecting all the links

How would you select all the links inside a certain div, using jquery?

<div id="content">
     
    <!-- SELECT ALL LINKS IN THIS DIV -->
     
    <a href=开发者_如何学Python"mysite.com">My site</a>
    <a href="mysite.com">Link 2</a>
     
</div>

<div id="footer">
    <a href="alink.com">Don't select any links from this div</a>
</div>


Lee, the problem with that, is that if you have an anchor, you will be selecting it too..

Have you noticed how you could this too? It's a bit safer I would say...

$('#content a[href]')

In case you had a simple anchor you wouldn't want selected..


$('#content a')

where content is the id of the <div> that holds the <a> elements that you want to select.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜