Reputation: 1122
<div class="cdlButton" style="width:40px; float: left;"> // want this div element
<div style="">
<a id="changestatus" class="" onclick="changeWorkflowStatus()" href="#">
<img id="" width="32px" height="32px" title="disable" alt="disable" src="images/disable.png">
</a>
</div>
</div>
I want div with help of jquery Right now i am doing this way
$("#changestatus ").parent().parent().addClass('disablecdlButton');
Is there any other way to get top div element
Upvotes: 2
Views: 102
Reputation: 133403
You can try
$("#changestatus ").parents(".cdlButton").addClass('disablecdlButton');
Upvotes: 1
Reputation: 4624
Try this, .parents('div').last()
will select the top most parent div element of the selected element , here it is changestatus
$("#changestatus ").parents('div').last().addClass('disablecdlButton');
Hope this helps,Thank you
Upvotes: 0
Reputation: 1064
$("#changestatus ").parents('div.cdlButton').addClass('disablecdlButton');
Upvotes: 0
Reputation: 8954
You can do various things here
$(".cdlButton").addClass('disablecdlButton');
$('#changestatus').closest('div.cdlButton').addClass('disablecdlButton');
$($('#changestatus').parents().get(-1)).addClass('disablecdlButton');
Upvotes: 2
Reputation: 27354
$('#changestatus').closest('div.cdlButton').addClass('disablecdlButton');
For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
Upvotes: 7
Reputation: 121998
use closest()
Description: For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
$("#changestatus").closest("div.cdlButton").addClass('disablecdlButton');
Upvotes: 1