Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Изменить класс с помощью select (https://javascript.ru/forum/dom-window/19278-izmenit-klass-s-pomoshhyu-select.html)

Karlen 31.07.2011 03:23

Изменить класс с помощью select
 
Помогите решить задачу:

Имеются Элементы:
<div class="box red">Text</div>

<select id="select_color" tabindex="0" name="select_color">
	<option value="red">Красный</option>
	<option value="blue">Синий</option>
	...
	<option value="white">Белый</option>
</select>


Решить задачу следующим образом не подходит( мне нужно именно добавление класса.

var xXx = document.getElementById('box');
var select = document.getElementById('select_color');
xXx.style.background = select.options[select.selectedIndex].value;


Наверное лучше реализовать через document.write()? Как это сделать грамотно?

http://jsfiddle.net/DvbHn/

Octane 31.07.2011 08:03

http://javascript.ru/unsorted/top-10...s#comment-5940

melky 31.07.2011 09:36

http://jsfiddle.net/DvbHn/1/

*!*
var xXx = document.querySelector('.box');
*/!*
var select = document.getElementById('select_color');

select.onchange = function(){
    xXx.style.background = select.options[select.selectedIndex].value;
}

Karlen 31.07.2011 10:02

Спасибо


Часовой пояс GMT +3, время: 19:23.