0

I am designing a page that retrieves data from database and displays it in tabular format in brief. There is a hyperlink and clicking on it displays the details of a record.

here is some code

for (var i = 0; i < n; i++) { 
   result = result + "<tr><td><a href='javascript:void(0)' class='detailStud' iditem='"
     + response.studs[i].regd+"'>Details</a></td></tr>";
}

on JQuery side

$('.detailStud').click(function(){

var val1= $(this).attr('iditem');

alert(val1);});

But this is not working.... please help ....

user2915097
  • 30,758
  • 6
  • 57
  • 59
Rakesh Ray
  • 62
  • 1
  • 9
  • 1
    is it returning undefined in alert or alert is not thrown – Janani Kumar Jul 28 '16 at 12:10
  • [Use `data-*` attributes](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes), and retrieve them with `$(this).data('iditem')`. – moonwave99 Jul 28 '16 at 12:12
  • 1
    What exactly is your problem? That you are able to get the element value of only one of the element but you want the values of all the elements with the same class name? Or are you getting no values at all? Or are getting some error with the above code? – Ankush Raghuvanshi Jul 28 '16 at 12:13
  • *"this is not working"* is not proper problem statement. If event delegation doesn't solve problem then update question with proper explanation and [mcve] – charlietfl Jul 28 '16 at 12:15
  • Thanks Mr Ben $('#listStudDiv').on("click","a.detailStud",function(){ alert($(this).attr('iditem')); }); – Rakesh Ray Jul 28 '16 at 12:25

0 Answers0