Generic Anchor
  • Some text More stuff

    Remove tags (and tag content) but leave text

    Given this kind of HTML:

    <div> <a href="#">Generic Anchor</a> <li> Some text </li> <b> More stuff </b> Just text. </div> 

    If the tags are random, there is a way in jQuery (or Javascript) to reduce it to ONLY text, which means

     <div> Just text. </div> 

    Without specifying specific tags for the strip (I know .text (), but I do not want the contents of the tags I delete).

    +4
    source share
    1 answer

    Try the following: http://jsfiddle.net/5SRLE/1/

     $("div").children().remove(); 

    Of course, you need to target a specific div to this selector (if you have other divs from which you don't want to remove children). If you have problems, show your context so that we can make it more specific ... or give your div id as myDiv , and then use the $("#myDiv") selector instead of $("div")

    +5
    source

    Source: https://habr.com/ru/post/1489779/


    All Articles