Skip to content Skip to sidebar Skip to footer

Get The Id Of A The Item That Is Clicked

I have this html code: FOOFOO2FOO3 And

Solution 1:

I'm assuming from your sample code that you're using jQuery? If so you can get the id as follows:

$('b.edit').click(function(){
 this.id;
});

EDIT:

The direct reference to the attribute is indeed more efficient if all that is required is simply the id.

Also can be obtained from the jQuery object:

$('b.edit').click(function(){
 $(this).attr('id');
});

Sample fiddle: http://jsfiddle.net/5bQQT/

Solution 2:

Try with this:

$('b.edit').click(function(e){ //When you use an event is better//send the event variable to the //binding function.var id = e.target.id; //get the id of the clicked element./*do your stuff*/
    $('.editP').focus();
});

Solution 3:

try this. You can use keyword "this" to retrieve the attr ID...

$('b.edit').click(function(){alert($(this).attr("id"));});

Solution 4:

$('.edit').click(function(){
   var theId = $(this).attr('id');
}

This will get you the ID of anything clicked with a class of .edit

Solution 5:

$('.edit').live('click', function() {
    alert( this.id );
});

Samplehttp://jsfiddle.net/ck2Xk/

Post a Comment for "Get The Id Of A The Item That Is Clicked"