I have such a JS code :
var parent = titles[i].parentElement;
console.log(parent.innerHTML);
That prints this on console :
<title style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">MyTitle</title>
How can I change MyTitle
to something else? Thanks.
EDIT :
My whole code is this:
var titles = document.getElementsByTagName('title');
for (var i = 0; i < titles.length; i++) {
if (titles[i].innerHTML == 'MyTitle') {
console.log(titles[i].innerHTML);
var parent = titles[i].parentElement;
console.log(parent.innerHTML);
titles[i].innerHTML == '1215546162';
console.log(titles[i].innerHTML);
$(parent).attr('fill', 'blue');
}
}
Maybe this helps:
titles[i].innerHTML="New Title";
Title is changing (look at console) at this fiddle: https://jsfiddle.net/ek6f9jq8/2/
I don't know the the exact purpose of your code, but this can be helpful.
var head = document.getElementsByTagName("head")[0];
var title = head.getElementsByTagName("title")[0];
title.innerHTML = "Foo";
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.