jquery click & get value of attributes of a href

How can I access seq value in a href, when I click thye link?

/* Add a listner to Group buttons */ $('a.preActNav').click(function() { alert(this.seq) }); <li><a href="#preclose4" seq='1'>A</a></li> <li><a href="#preclose4" seq='2'>B</a></li>

5 Answers

Like this:

alert($(this).attr('seq'));

Although it may be better to put seq as another data element:

<li><a href="#preclose4" data-seq='1'>A</a></li>

So then you can do:

alert($(this).data('seq'));

2

Have you tried: $(this).attr()?

try the following

$('a.preActNav').click(function() { alert($(this).attr('seq'));
});

you need to use $(this) jquery selector instead

Try this

$('a.preActNav').click(function() { alert($(this).attr('seq')); //To get href alert(this.href); }); 

you can either use this code:

 $('.item').click(function(){ console.log($(this).attr("name")); });

or

$('.item').on('click', () => { console.log($(".item.active").attr("name"));
});

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like