Reputation: 357
Hi I am using following code to attach event to links on the page.
$(document).ready(function(){
$("a").click(function(){
..... do something
});
});
But I don't want to do this for all the links. I want to do this for few selected links. Can anyone help how can I achieve this?
Upvotes: 0
Views: 72
Reputation: 14859
Add a class
to the links you want to affect, then change your selector to $('a.className')
.
Upvotes: 0
Reputation: 140843
$(document).ready(function(){
$(".className1").click(function(){ /*Action1*/ });
//or
$("#id1").click(function(){ /*Action2*/ });
});
Upvotes: 0
Reputation: 4888
Refine your selector - instead of all links, target them by class, id, or parent etc.
$(document).ready(function(){
$(".myClass1, .myClass2, #myId").click(function(){
..... do something
}); });
Upvotes: 0
Reputation: 6127
Add a class to all of the links you want to add click events for, then:
$('.thatClassName').click(function(){ ... });
Upvotes: 3