How can I select a specific anchor tag using jquery?

I have two types of anchor tags that you can see.

First:

<a>Link</a> 

and second:

 <a href="http://facebook.com"></a> <a href="http://twitter.com"></a> 

I just want to select only tags of this type <a>Link</a> using jquery.

+4
source share
2 answers

You should use the :not css selector:

 $('a:not([href])') 

Select all a tags without href attribute

jQuery docs here

+5
source
 $('a').filter(function(){ return !$(this).attr('href'); }); 

Working example: http://jsfiddle.net/3Sczq/

+6
source

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


All Articles