javascript - how can i make remove this parent , but dont want to skill 1 or 2 chirldren? -
i have code below:
<ul class="history"> <li class="hello"></li> <li class="hi"></li> <li class="yello"></li> <div class="baby"></div> <div class="kitty"></div> </ul> now want remove elements in ul, want hold 1 div or li (ex: div.baby) how can now? want use click function.
with jquery:
var babyelement = $('.baby') // save element later $('.yellow').remove() // remove element with javascript:
var babyelement = document.queryselector('.baby') var yellowelement = document.queryselector('.yellow') if (yellowelement.parentnode) { yellowelement.parentnode.removechild(yellowelement) } https://developer.mozilla.org/en-us/docs/web/api/node/removechild
Comments
Post a Comment