简体   繁体   中英

javascript innerHTML end tag case

I used 'tag'.innerHTML .it will render with adding an endtag.How can i get only the display content inside a selected tag html?

<div id="tabs">
    <ul class="tabs">
    <li class="current"><a><span>News</span></a></li>
    <li><a><span>Videos</span></a></li>
    <li><a><span>Photos</span></a></li>
    <li><a><span>Twitter</span></a></li>
    </ul>
</div>

actually i need to get code like this by js between <pre> tags

Look at this :

http://jsfiddle.net/qGyf6/

HTML :

<li><a><span><b>News</b></span></a></li>

jQuery :

var pureText = $("li").text();
var val = $("li").val();
var html = $("li").html();

if you mean the text without the HTML tags, you may use

$('tag').text()

Reference

你应该使用text()代替,这将只返回文本

在纯JavaScript您可以使用innerText

'tag'.innerText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM