Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i select specific anchor tag using jquery?

Tags:

html

jquery

i have two types of anchor tag as 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 this type tags <a>Link</a> using jquery.

like image 325
Muhammad Furqan Avatar asked Dec 20 '22 14:12

Muhammad Furqan


2 Answers

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

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

like image 116
ianaz Avatar answered Jan 07 '23 18:01

ianaz


You should use the :not css selector:

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

Select all a tags without an attribute href

jQuery docs here

like image 40
Elliott Avatar answered Jan 07 '23 16:01

Elliott