[removed] how to remove element on title

2019-07-21 21:20发布

问题:

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:

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


回答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();


回答3:

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


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