Just want to remove highlight class before applying class again on other elements. Reseting the selected items. How?
removeClass not working in the below code.
$("#toggleCustom").on("click", function () {
var $this = $(this),
$domtree = $this.parents('div.section').find('div.domtree'),
query = $this.prev().val();
//$domtree.removeClass('highlight').animate({ marginLeft: 0 }, 'fast');
$domtree.find(query).addClass('highlight').animate({ marginLeft: 10 }, 'fast');
});
removeClassacts only on the elements in the matched set of the jQuery instance you call it on; not on descendants of that set. From your code:…it looks like the class is actually applied to descendant element(s) (e.g., ones matching the selector in
query).You can find and remove it on all descendants like this: