Is there a way to remove title tag using javascript?
I tried to do this
var parent = document.head; var child = document.title; parent.removeChild(child);
but it failed because title tag is not a node (console said). I need to force a WordPress plugin to overwrite the default title tag with a custom one.
Any ideas?
Advertisement
Answer
The title
property just contains a string representation of the title. It doesn’t represent the element itself.
You can use any of the usual methods to get the element itself.
document.querySelector("title"); document.getElementsByTagName("title")[0] // etc