Reputation: 59
I wanted to load (replace) text from <h2>
<h2>Text</h2>
to
<title>Here!</title>
How can I do it?
When I was replacing classes I used something like $(".value").load
...
but I don't know how to do that with tags.
Thanks
Upvotes: 3
Views: 65
Reputation: 7280
You can set the title using the document.title
property. So setting the title to be the content of a h2
tag you could use:
document.title = $('h2').text();
Without jQuery
var element = document.getElementsByTagName('h2')[0];
if (element.textContent) {
document.title = element.textContent;
} else {
document.title = element.innerText; // IE < 9
}
Upvotes: 3