154
rated 0 times
[
156]
[
2]
/ answers: 1 / hits: 40845
/ 10 Years ago, wed, july 2, 2014, 12:00:00
How can i get Parent Div id of component.
I have already referred this link but its not working.
jQuery get id of element by searching for it by class
Here Is my Sample Code.
<html>
<head>
<script src=http://code.jquery.com/jquery-latest.min.js></script>
<script>
function linkClickEvent()
{
alert ($(this).parent().attr('id')); //Gives Me Undefined
alert($(this).closest('div').attr('id')); //Gives Me Undefined
alert($(this).parent().attr('id')); //Gives Me Undefined
}
</script>
</head>
<body>
<div id=container_1>
<a href=# onclick=linkClickEvent(); id=link_1>Container_1</a>
</div>
<div id=container_2>
<a href=# onclick=linkClickEvent(); id=link_2>Container_2</a>
</div>
<div id=container_3>
<a href=# onclick=linkClickEvent(); id=link_3>Container_3</a>
</div>
</body>
</html>
More From » jquery