Tutorial :javascript: how to remove element on title



Question:

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


Solution:1

$("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();  


Solution:2

Do:

// get the title from the div and apply to the title tag and then remove div  $('div#title').parent().html($(this).text()).remove();  


Solution:3

var tag = /(\<.*?\>)/g;  document.title = document.title.replace( tag, "" );  


Solution:4

<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);  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »