jQuery Select Element that has no Class or ID

后端 未结 3 941
时光说笑
时光说笑 2020-12-21 07:41

Trying to find a selector to get all elements that have both no class, and no id set to them.

So far I have 2 different outputs depending on if there is a space in

3条回答
  •  情深已故
    2020-12-21 08:28

    withSpace - $('*:not([id]) *:not([class])'); will find all elements with no class that are inside an element without an ID. Putting a space in the selector is like calling find seperately.

    You could change noSpace to be this instead and still get the right result:

    var noSpace= $('*:not([id]):not([class])'); // second * not needed
    

    JSFiddle used for testing

提交回复
热议问题