There is a select with 2 white and black values.

You need to change the value of the white class to the black class and back to white, depending on the selection. On all div

<select id="sel" name="sel" class="theme"> <option value="white">white</option> <option value="black">black</option> </select> <div class='white'> main <div class='white'> content1 </div> <div class='white'> content2 </div> 

Javascript or jquery

Please, help.

  • Our working language is Russian. Therefore, please contact us to intl. SO . - 0xdb
  • Thank you confused, now I will write in Russian - Pavel Tk

2 answers 2

 $("#sel").change(function(){ $("div").removeClass("white black").addClass($(this).val()); }); $("#sel").change(); 
 .white{ color:red; } .black{ color:green; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select id="sel" name="sel" class="theme"> <option value="white">white</option> <option value="black">black</option> </select> <div> main </div> <div> content1 </div> <div> content2 </div> 

  • Thank you very much, this is just what you need. All ingenious is simple. And that he could not figure out how to do this with select. - Pavel Tk
  • @PavelTk Please. Successes! A tick on the left - click :). - Igor
  • Thanks for the tick, also could not figure out how to mark your code. :))))) - Pavel Tk

 .white{ color:red; } .black{ color:green; } 
 <select name="sel" class="theme" onchange="sel.className = this.value"> <option value="white">white</option> <option value="black">black</option> </select> <div id="sel" class='white'> content </div> 

  • Thank you very much, I changed the question a little, I just need to change not on one Div but on several. - Pavel Tk