0

I'm looking for a cross-browser way to clear/remove/delete a dynamically created ul (with li-posts)-list.

created as such: document.createElement("ul");

Is there a truly cross-browser method implemented?

Edit: JQuery not allowed.

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
BSG
  • 1,382
  • 4
  • 14
  • 25

5 Answers5

4
// assuming you created your `ul` like this
var ul = document.createElement('ul');
document.body.appendChild(ul);

If you just want to remove its content

// removing only its content
ul.innerHTML = "";

Or you can remove both element and content like this

// removing element and content
ul.parentNode.removeChild(ul); 
Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
lostsource
  • 21,070
  • 8
  • 66
  • 88
1

use removeChild

var createdUL=document.createElement("ul"); 
createdUL.parentNode.removeChild(ul);
bipen
  • 36,319
  • 9
  • 49
  • 62
1

Seems this link might be help you. But remember your question is clear to understand but you have to post some code also to check for the possibilities. Try the following link. JavaScript DOM remove element

Community
  • 1
  • 1
Faizul Hasan
  • 625
  • 1
  • 7
  • 17
1

You can how use replaceChildren to accomplish this:

ul.replaceChildren();
ParadoxFox
  • 133
  • 1
  • 8
0

JQuery remove?

$("ul").remove();

Content remove:

$("ul *").remove();
Tymek
  • 3,000
  • 1
  • 25
  • 46