How to get html() from element excluding another element?

后端 未结 2 1721
庸人自扰
庸人自扰 2021-01-13 06:21

Sorry for real stupid question. But it does not work either way.





        
相关标签:
2条回答
  • 2021-01-13 06:29

    This should do it:

    var clone = $('div.content').clone();
    clone.find('.dontgrab').remove();
    
    var html = clone.html();
    
    0 讨论(0)
  • 2021-01-13 06:50

    I think you are trying to do:

    var htmlcontent = $('.content').remove(".dontgrab").html();
    

    You could use .not() if the situation was like:

    var htmlcontent = $('div').not(".dontgrab").html();
    
    <body>
    <div class="content">
      BEFORE  
    
      AFTER
    </div>
    <div class="content dontgrab">DON'T GRAB</div>
    </body> 
    

    I dont think you can use .not for selected elements children. I hope it helps

    0 讨论(0)
提交回复
热议问题