javascript:如何删除标题上的元素

时间:2010-06-30 21:35:25

标签: javascript jquery dom title

作为标题,如何使用javascript或jquery框架删除html标题上的div? 我知道这听起来很奇怪,但目前我正在研究CMS模板,并且生成标题围绕标题

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

任何帮助表示赞赏

4 个答案:

答案 0 :(得分:1)

执行:

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

答案 1 :(得分:1)

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

答案 2 :(得分:0)

&lt; title&gt;页面标题&lt; / title&gt; 去除div标签

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

或&lt; title&gt;&lt; / title&gt; 如果你想删除整个div

var title = document.getElementById("title");
title.parentNode.removeChild(title);

答案 3 :(得分:0)

$("title").text($("<div/>").html($("title").text()).text());

将原始标题标记的(不合适的)HTML文本存储到临时div中,然后将临时div的纯文本内容放回标题中。

编辑:也可能是适用于IE6的更好的解决方案:

document.title = $("<div/>").html(document.title).text();
相关问题