How to remove all siblings in JavaScript? -
i have 4 images , want remove other 3 when clicked.
i 1 one with:
function removeimages() { var elem = document.getelementbyid('image1'); elem.parentnode.removechild(elem); }
but not practical.
what best way remove siblings (images) except 1 clicked?
why don't try use jquery manipulate dom? easier , supported browsers. code follows:
$("#imgcontainer img").click(function () { $(this).siblings().remove(); });
please have @ working version: js fiddle
Comments
Post a Comment