开发者

Remove div using just classname

开发者 https://www.devze.com 2022-12-26 13:49 出处:网络
I want to remove below element using javascript/jquery. <p class=\"classname\"><a title=\"some title\" href=\"#\">Hello</a></p>

I want to remove below element using javascript/jquery.

<p class="classname"><a title="some title" href="#">Hello</a></p>

Please note that I don't have the id of the element so how ca开发者_如何学编程n I remove it using just the class name.


$('.classname').remove();
// OR
$([container selector]).remove('.classname');

according to the jQuery documentation.


you can select items by their class using the following syntax

$(".classname")

So to remove this item it would be

$('.classname').remove();


If the link is unique but the paragraph with the classname is not and you only want to remove this single element, search for the link first:

$("a:contains('Hello')").parent().remove();
0

精彩评论

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