Skip to content

How to remove elements which i find with find() jQuery?

I have an element in which i want to find a specific class and remove those class.

example

editingElm = `<p><span class="editing-target">hello</span><span class="editing-target">Welcome to this virtual world</span></p>`

 let elements = editingElm.find('.editing-target');// elements= [span,span] with the class
    editingElm.removeClass('editing-target');

How can i loop over the elements array and remove those classes i found?

Answer

Thanks to @Carsten Løvbo Andersen

You can’t do editingElm.find(‘.editing-target’) since based on your code, it’s a string.
you have to do $(editingElm).find(‘.editing-target’) and
editingElm = $(editingElm).find(‘.editing-target’).removeClass(“editing-target”)

$(editingElm).find('.editing-target').removeClass("editing-target")