How To Find Child Div Id onClick Of Parent Div ?

Jquery_logo


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:
<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/2/
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