views:

96

answers:

4

Hi everyone,

As the title, how can I remove a div on the html title using javascript or jquery framework? I know it sounds weird but currently I'm working on a CMS template and the generate title has around the title

<title><div id="title">Title of the page</div></title>

Any help appreciated

+1  A: 

Do:

// get the title from the div and apply to the title tag and then remove div
$('div#title').parent().html($(this).text()).remove();
Sarfraz
Thanks sAc .....
Bob
A: 

<title>Title of the page</title> to strip the div tags

var title = document.getElementsByTagName("title")[0];
title.innerHTML = title.firstChild.innerHTML;

or <title></title> If you want to remove the whole div

var title = document.getElementById("title");
title.parentNode.removeChild(title);
galambalazs
Neither of your solutions work for me. Which browsers did you test in?
patrick dw
Bob
A: 
$("title").text($("<div/>").html($("title").text()).text());

Stores the (inappropriate) HTML text of the original title tag into a temporary div, then puts the plain-text content of the temporary div back into the title.

EDIT: Probably a better solution that works on IE6 as well:

document.title = $("<div/>").html(document.title).text();
Sean
Awesome, it works perfectly! Thanks dude
Bob
@Bob - Make sure this works for you in IE (if needed). I don't think it does.
patrick dw
@patrick, you're right the previous code didn't work on IE, thanks for the update Sean. You're a legend!
Bob
+1  A: 
var tag = /(\<.*?\>)/g;
document.title = document.title.replace( tag, "" );
yulerz
+1 - Cleaner than mine (deleted). Not sure why I didn't use `document.title` to get the text of the title. And works cross-browser unlike the others.
patrick dw
Thanks yulerz :)
Bob
@Bob - This answer from yulerz will give you better performance.
patrick dw