How to change element class on select option using jQuery

前端 未结 3 1633
南方客
南方客 2021-01-14 00:02

I want change my class=\"value\" on select option using jQuery

Example


                        
    
提交评论

  • 2021-01-14 00:40

    use the change event to determine when the user selected another option. To remove all current classes, call removeClass() with no arguments. Finally add the new class, which can be accessed by this.value.

    $('#color_scheme').change(function(e) {
        $('span').removeClass().addClass(this.value);
    });
    

    Demo: http://www.jsfiddle.net/4yUqL/100/

    0 讨论(0)
  • 2021-01-14 00:41

    Try:

    $('p').removeClass('myClass noClass').addClass('yourClass');
    
    0 讨论(0)
  • 提交回复
    热议问题