Miro Grujin
Miro Grujin

Reputation: 716

javascript remove or replace completely HTML tag

I try to delete or replace this HTML tag from my code.

<li class="li-sortable-background">

I have try with replace, but i replace only text and can't replace code characters like <=""> and stuff. I need help please!

Upvotes: 0

Views: 269

Answers (5)

Sachin Kumar
Sachin Kumar

Reputation: 69

$( ".li-sortable-background" ).replaceWith("<h2>your vale</h2>");

Upvotes: 0

Abhijeet
Abhijeet

Reputation: 4309

You can use following code

Using JQuery :

$("#div1").remove();

Removing elements by class name:

$('.className').remove();

Using javascript :

var child = document.getElementById("divId");
child.parentNode.removeChild(child);

Upvotes: 0

Miro Grujin
Miro Grujin

Reputation: 716

Sorry, its a string like this and i give it out in a textarea value. I just want to remove LI with class etc.

<form name="asd" id="freeld_form" class="sortable ui-sortable" action="" method="get">
<li class="li-sortable-background">
<label for="asd" id="aha"></label>
<input name="asd" id="asd" class="" placeholder="" type="">
<button class="deleteButton"><img src="images/delete-button.svg" title="Load File"></button>
</li>
</form>

Upvotes: 0

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14604

Try this. Supposing that you have only one element with this class.

document.getElementsByClassName('li-sortable-background')[0].remove()

Upvotes: 0

shobhit jain
shobhit jain

Reputation: 141

Use .remove() method when you want to remove the element itself, as well as everything inside it.

Upvotes: 2

Related Questions