jquery - get the class of the parent html element -
hi guys i'm trying class of parent element of element clicked
ex:
<div class="mydiv"><a href="#" class="link">click me</a></div>
i want class of parent div(mydiv)
i tried didn't work:
$(document).ready(function(){ $(".link").click(function(){ var div=$(this).parent().classname; alert(div); }); });
it gives me (undefined). 1 can help?
.parent()
gives jquery object , classname property of dom element try:
var div=$(this).parent()[0].classname; // use [0] dom element , property
or
var div= $(this).parent().attr("class"); //use jquery attr value of attribute class
Comments
Post a Comment