Reputation: 115
i used this below function...for each id i call one function..i call only one click function at a time so i need to use single click function for this..
.append($('<a>',{'class':'list-header','id':'call1','name':'name','value':'1'}).append('1'))
.append($('<a>',{'class':'list-header','id':'call2','name':'name','value':'2}).append('2'))
...
...
...
.append($('<a>',{'class':'list-header','id':'call7','name':'name','value':'7'}).append('7'))));
$('#call1').click(function(){
});
$('#call2').click(function(){
});
...
...
...
$('#call7').click(function(){
});
i have use seven function above..i will call only one function at a time. so i need to do it in a single function..
how to do it?
Upvotes: 1
Views: 135
Reputation: 4864
Attach click event for all objects by class selection.
$(document).ready(function() {
$(".list-header").click(function(clkEvt) {
var ClickedAtag = $(clkEvt.target);
alert(ClickedAtag.id);
});
});
ClickedAtag
is the element that clicked by the user. You can use this object to do any unique function for the clicked element.
Upvotes: 0
Reputation: 121998
you can try
$('#call1, #call2, #call3, #call4,#call5,#call6,#call7').
click(function(event){
if($(event.target).attr('id')=='call1'){
/* specific code for call1*/
} else if($(event.target).attr('id')=='call2'){
/* specific code for call2*/
------
});
Upvotes: 0