开发者

Remove element by class using parent()

I am making changes to a jQuery validator开发者_如何学JAVA, 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.


.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');


Try

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜