Alex Rivera | Logout

How do I use jQuery get the ID of the div which has been clicked on?

Asked 2012-06-28T16:20:35.457
15

I need to get the ID of the clicked-on div.

Now when I click on status class I an returned undefined id.

Here is my javascript code

jQuery(document).ready(function() {
    $(".status").bind('click', $.proxy(function() {
        var status = $(this).attr('id');
        alert(status);
    }, this));
});​

and HTML

<div class="status" id="s_1">111111</div>
<div class="status" id="s_3">33333</div>
<div class="status" id="s_2">222222</div>

How should I get the correct id value?

Edit
Report

1 Answer

0
$('selector').each(function(){
    $(this).click(function(){
        alert($(this).attr('id'))
    });
});
answered 2013-06-06T07:23:18.157

Your Answer