javascript: how to remove element on title

不想你离开。 提交于 2019-12-11 03:48:38

问题


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


来源:https://stackoverflow.com/questions/3153611/javascript-how-to-remove-element-on-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!