How do I use jQuery to select all children except a select element

后端 未结 7 880
甜味超标
甜味超标 2020-12-07 18:43

I have a div (let\'s say the id is \"container\") with many elements in it, including a select element. I\'d like to select all everything in the div except the select. Thin

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 19:08

    It is not clear what you actually want from your question. :not(select) will filter out the select from all the descendants but it will not out the select descendants. If this is your issue then try the following

    Demo

    $("#container *").filter( function(){ 
        return $(this).closest('select').length === 0 
    })
    

提交回复
热议问题