jQuery Remove CSS Class from all Descendants at once

后端 未结 4 1084
花落未央
花落未央 2021-02-13 13:48

Can I remove a specific CSS class from all XYZ elements within an element at once?

Example: Remove CSS class active from all

4条回答
  •  广开言路
    2021-02-13 14:53

    A more generic solution to remove the class from any possible element.

    // I like to use find as I usually have my wrapper in a variable.
    $('#my-wrapper').find('.active').removeClass('active');
    

    Or

    $('#my-wrapper .active').removeClass('active');
    

    This will affect all elements within the wrapper: span, h3, div, li, td, etc. With html 5 there are now over 100 possible tags.

提交回复
热议问题