Jquery gets target value for href

Using jquery how to know the target value of a href link. for example if my link was

<a href="someurl.com" id="the_link" target="_blank">link</a>

target will be _blank

+3
source share
5 answers

Using attr ()

$('#the_link').attr('target');

Jsfiddle example .

+9
source

I will be different and will teach you partially vanilla js, acting directly on the properties of the elements:

$('#the_link')[0].target;

If you use jQuery> = 1.6 you should use .propthan .attrreally

$('#the_link').prop('target');
+5
source

Use attr ()

alert($('#the_link').attr('target'));
+1
source

Simply

$('#the_link').attr('target');
+1
source
$('a').attr('target')

Gotta do it

( jQuery.attr Documentation )

0
source

All Articles