Reputation: 32331
When clicked on a checkbox , i am trying to find the root div class of that element
I was trying with different options ,but for all of them i am getting undefined .
$(document).on("click", ".checkboxclas", function(e) {
var cls = $(this).find('div:first').attr('class') ;
alert(cls)
});
When clicked on activateUiHTML checkbox, i wanted to display activateUiHTMLparentdivclass
When clicked on ordersdiv checkbox , i wanted to display parentsordersdivclass
could anybody please tell me how to do this .
Upvotes: 2
Views: 537
Reputation: 67207
Try to use .parents().last()
to find the last parent element, I think you have some confusion with what is a root element is.
$(document).on("click", ".checkboxclas", function(e) {
var cls = $(this).parents('div').last().attr('class') ;
alert(cls);
});
Upvotes: 2
Reputation: 2815
change
var cls = $(this).find('div:first').attr('class') ;
to
var cls = $(this).closest('div').attr('class') ;
Upvotes: 1