javascript - IE issue while replacing title tag content with another title tag content using jquery -


i have page has 2 title tags (this due @ run time include page in page). seeing first title tag value in browser want show second title tag's value. here code have, working fine in firefox , chrome not in ie7. suggestions?

var titlename; $(document).find('title').each(function(){     titlename = $(this).text(); }); $(document).attr("title", titlename); 

you don't need jquery this. should work in ie (as other browsers) using vanilla javascript.

document.title = 'new title'; 

because of how ie handles <title> element, you'll need give little in getting second value.

var titlename; // find title elements using plain ol' javascript var titles = document.getelementsbytagname('title');  // iterate on array of titles $.each(titles, function(i, title) {     // if there childnodes, know we're not in ie     if (!!title.childnodes.length) {         titlename = title.firstchild.data;     }     // in ie, can read title elements innerhtml, can't set     else if (title.innterhtml) {         titlename = title.innerhtml;     } }); // finally, set document title document.title = titlename; 

the major issue here title element in ie doesn't have child nodes, $(this).text() won't work.

let me know if above code works you.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -