Getting the contents of an element WITHOUT its children

前端 未结 5 1453
醉话见心
醉话见心 2020-12-10 11:18

I have a mild preference in solving this in pure JS, but if the jQuery version is simpler, then jQuery is fine too. Effectively the situation is like this

&l         


        
5条回答
  •  粉色の甜心
    2020-12-10 12:01

    FROM: http://viralpatel.net/blogs/2011/02/jquery-get-text-element-without-child-element.html

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

提交回复
热议问题