Here I am explaining how to find the parent element's id of a html element using jquery function.
$(this).parent().attr(''id);
this jquery function will give the "id" of the given element's parent element.
eg:
<html>
<script>
$("a").click(function(){
var parentid = $(this).parent().attr(''id");
});
</script>
<body>
<div id="parent-id" class="parent-class">
<a href="#">test</a>
</div>
</body>
</html>
the variable "parentid" will return the value parent-id
$(this).parent().attr(''id);
this jquery function will give the "id" of the given element's parent element.
eg:
<html>
<script>
$("a").click(function(){
var parentid = $(this).parent().attr(''id");
});
</script>
<body>
<div id="parent-id" class="parent-class">
<a href="#">test</a>
</div>
</body>
</html>
the variable "parentid" will return the value parent-id
0 comments:
Post a Comment