Remove div using just class name

I want to remove the element below using javascript / jquery.

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

      

Please note that I don't have an element id, so how can it be removed using just the class name.

+2


source to share


3 answers


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

      



according to the jQuery documentation .

+8


source


you can select elements by their class using the following syntax

$(".classname")

      



So, to remove this item it would be

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

      

0


source


If the link is unique, but there is no paragraph with the class name, and you want to remove that single element, first find the link:

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

      

0


source







All Articles