开发者

Clip content with jQuery

to just get the number inside span, use the code below:

开发者_运维问答
<h3>test <span>inside 123458</span></h3>


alert($('h3 span').text().match(/\d/))
//123458

And to just get the content h3, without taking the span of content, how?


jQuery solution

alert( $('h3').clone().find('span').remove().end().text() );

pure JS solution

alert( document.getElementsByTagName('h3')[0].childNodes[0].textContent );

examples : http://jsfiddle.net/2mTLg/1


If you want to parse just the number then try this:

<h3>test <span>inside 123458</span></h3>

<script type='text/javascript'>
    alert($('h3 span').text().match(/\d+/));
</script>

Hope this helps. Here is a jsFiddle to play with: http://jsfiddle.net/pkMB2/1/

Bob

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜