js通過className刪除元素


有時候難免需要使用js進行 dom 操作;如在刪除地圖feature時同時得清除提示框
在這里插入圖片描述
這個就需要使用 .parentNode.removeChild(元素)


	let chArr = document.body.getElementsByClassName("tooltip-static");
	for(i=0;i<chArr.length;i++){
	     //刪除元素 元素.parentNode.removeChild(元素);
	    if (chArr[i] != null) 
	          chArr[i].parentNode.removeChild(chArr[i]); 
	}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM