Prashant
Prashant

Reputation: 21

Remove div using just classname

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 can I remove it using just the class name.

Upvotes: 2

Views: 9853

Answers (3)

Felix Kling
Felix Kling

Reputation: 816422

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();

Upvotes: 0

Tomas Aschan
Tomas Aschan

Reputation: 60584

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

according to the jQuery documentation.

Upvotes: 8

corymathews
corymathews

Reputation: 12619

you can select items by their class using the following syntax

$(".classname")

So to remove this item it would be

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

Upvotes: 0

Related Questions