if this is my div element
<a href="sdfsfsf"><p class="quotes">blablabla</p></a>
If it is not homepage, how can you delete parent a for this quotes
i could not configure this code for my element:
function delete_row(e)
{
e.parentNode.parentNode.parentNode.removeChild(e.parentNode.parentNode);
}
js program must be automatically loaded also when page is loaded and it is not home page, it should delete a element
要删除子元素e
的直接父元素,而使子元素仍保留在DOM中(但重新绑定到其原始祖父母),请使用.replaceChild
:
e.parentNode.parentNode.replaceChild(e, e.parentNode);
If you want to leave p in place you need to add it to its parent's container first:
function delete_row(e) {
var parent = e.parentNode;
var grandParent = parent.parentNode;
// remove e from its parent
e.remove();
// insert e into its grandParent, before parent
grandParent.insertBefore(e, parent);
// remove parent
parent.remove();
}
But the same can be accomplished by the solution of @Alnitak above.
Today I've learned :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.