Home » » How to get div id from clicked div in Jquery ?

How to get div id from clicked div in Jquery ?

Rendyon | 10:19 PM | 0 comments
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:
1
2
3
<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>

Below is the jquery code for clicked div.

1
2
3
4
$('.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 this article :

0 comments:

 
Copyright © 2011. Find Updates - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger