Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting all the links

Tags:

html

jquery

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

<div id="content">
     
    <!-- SELECT ALL LINKS IN THIS DIV -->
     
    <a href="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>
like image 212
jonnnnnnnnnie Avatar asked Dec 13 '22 17:12

jonnnnnnnnnie


1 Answers

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..

like image 191
SomeDudeSomewhere Avatar answered Jan 12 '23 17:01

SomeDudeSomewhere