jQuery - Select everything except a single elements and its children?

后端 未结 6 1615
栀梦
栀梦 2020-12-10 03:47

I\'m trying to remove everything in the whole body, except of a single element and its children. How can I accomplish this?

Edit 1 Consider the foll

6条回答
  •  有刺的猬
    2020-12-10 04:04

    This code worked for me.

    $('body > * :not(#123)').remove()
    

    You need to give space between * and : . Earlier when try to use the code with

    $('body > *:not(#123)').remove() it did not work. I had to give space between * and : character.

    Happy coding.

提交回复
热议问题