万能的JQUERY

<li id="listItem">
    This is some text
    <span id="firstSpan">First span text</span>
    <span id="secondSpan">Second span text</span>
</li>

HTML代码结构如上,想要得到"listItem"第一级的文字,也就是"This is some text"。

方法如下:

$("#listItem")
    .clone()    //clone the element
    .children() //select all the children
    .remove()   //remove all the children
    .end()  //again go back to selected element
    .text();

万能的JQUERY啊!!!

posted on 2014-09-23 20:00  名可真难起  阅读(136)  评论(0)    收藏  举报