开发者

Selecting all the links

开发者 https://www.devze.com 2023-01-29 07:27 出处:网络
How would you select all the links inside a certain div, using jquery? <div id="content">

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

精彩评论

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