How to get div id from clicked div in Jquery ?

Jquery_logo


For using JQuery you have to download JQuery library .You can download it from here:
http://jquery.com/download/

and include it in head section of your page.
Sometimes we need clicked div id to perform some individual task on specific div according to div id. We can do it easily using Jquery. Jquery is very powerful and lightweight, JavaScript library.

Here is the example:
<div class="test" id="div_1">first div</div>
<div class="test" id="div_3">second div</div>
<div class="test" id="div_2">third div</div>

Jquery code for clicked div.
$('.test').click(function() {
var status = $(this).attr('id');
// To do whatever you want here
});

When you click on first div the above code will  id of that div, now can perform any task whatever you want.
Check running example here:

 http://jsfiddle.net/jeetu_verma11/uD2pM/
Reference:
http://jquery.com/
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment