DDan DDan - 4 months ago 7
Javascript Question

HTML class not removed

See my example here: https://jsfiddle.net/ddan/xvq6ofhh/

JS

$(function() {
var listEditPane = $('#editpane');

console.log($(listEditPane).find('.input-highlight').length); // 2
$(listEditPane).find('.input-highlight').removeClass('.input-highlight');
console.log($(listEditPane).find('.input-highlight').length); // still 2 ???
});


The class is not removed, the length is still staying the same. What am I missing?

$(listEditPane).find('.input-highlight').removeClass('.input-highlight');

Answer

The .removeClass() method expects the name(s) of the class(es) to remove, but you are passing a selector '.input-highlight'. Remove the . from the beginning:

$(listEditPane).find('.input-highlight').removeClass('input-highlight');

Demo: https://jsfiddle.net/xvq6ofhh/1/