GrantC
GrantC

Reputation: 81

Remove element by class using parent()

I am making changes to a jQuery validator, when there is an error it inserts a div to the parent element. I am trying to remove an the inserted div with by the specific class name from the parent.

$(element).parent().remove('.removeThis');

I thought the above code would work but it does not remove the the div.

Upvotes: 1

Views: 1073

Answers (2)

Andy E
Andy E

Reputation: 344575

.remove([selector]) will remove an element with the optional matching selector from the current list of elements in the jQuery object. It does not look through the children of the wrapped elements. Try either of these alternatives:

$(element).siblings('.removeThis').remove();
$(element).siblings().remove('.removeThis');

Upvotes: 1

kcostilow
kcostilow

Reputation: 146

Try

$(element).parent().find('.removeThis').remove()

Upvotes: 1

Related Questions