Home » » How To Find Child Div Id onClick Of Parent Div ?

How To Find Child Div Id onClick Of Parent Div ?

Rendyon | 2:31 AM | 0 comments
We can get child div id onClick of parent div easily by using find() and attr() function of JQuery.

Here is the example:
HTML code:
1
2
3
4
5
<div id='parentDiv' class='selectParent' style="height:15px;background-color:yellow;">
<div id="childDiv">
</div>
Click Me
</div>

JQuery Code:
-------------------------------
 $('.selectParent').click(function (){
var parentId=$(this).attr("id");
var childId=$(this).find("div").attr("id");
alert("parentDivId :["+parentId+"] childDivId :["+childId+"]");
});

Check live example Here: http://jsfiddle.net/jeetu_verma11/eZLS5/
Share this article :

0 comments:

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