Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  75] [ 7]  / answers: 1 / hits: 16890  / 11 Years ago, sat, june 15, 2013, 12:00:00
 $(#jqxTree-ReportGroups ul).append(<li id= + [data[i].Id] +  item-checked='true' item-expanded='true' class='treeLi'> 
<a class='report-tree-expand' href=''>+</a>
<a class='reportData' id='12345' href=''> + [data[i].Name] + </a></li>);


How to get the attribute value of id by class name reportData when its clicked?



EDIT:
click doesnt work.. If i use Live that function is getting called... How to do get the reportData's Id inside a live function


More From » jquery

 Answers
13

Take a look at this Code:



$(document).on('click' , '.reportData' , function(){
var idProp= $(this).prop('id'); // or attr()
var idAttr = $(this).attr('id');
console.log('using prop = ' + idProp + ' , using attr = ' + idAttr);
console.log();
return false; // to prevent the default action of the link also prevents bubbling
});


done use live it has been deprecated (on requires jquery version 1.7 and above)
but here is the code using live()



$('.reportData').live('click' , function(){
var idProp= $(this).prop('id'); // or attr()
var idAttr = $(this).attr('id');
console.log('using prop = ' + idProp + ' , using attr = ' + idAttr);
console.log();
return false; // to prevent the default action of the link also prevents bubbling
});


jsfiddle to prove working



http://jsfiddle.net/uvgW4/1/


[#77613] Thursday, June 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
coleman

Total Points: 518
Total Questions: 81
Total Answers: 96

Location: Aland Islands
Member since Wed, Nov 17, 2021
3 Years ago
;