Is there a way to remove title tag using javascript?
I tried to do this
JavaScript
x
4
1
var parent = document.head;
2
var child = document.title;
3
parent.removeChild(child);
4
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.
JavaScript
1
4
1
document.querySelector("title");
2
document.getElementsByTagName("title")[0]
3
// etc
4