<...">

Select All Links

How do you select all links inside a specific 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>
+3
source share
2 answers

Lee, the problem with this is that if you have an anchor, you will also choose it.

Did you notice how you could do this? I would say a little safer ...

$('#content a[href]')

In case you had a simple anchor, you will not want to choose.

+5
source
$('#content a')

where content- id <div>which contains the items <a>you want to select.

+7
source

Source: https://habr.com/ru/post/1778810/


All Articles