Изменять свойство класса в css
Простая функция и не понимаю почему не работает
let themeBlue = document.querySelector("#theme_blue"); let theme = document.querySelector(".theme"); themeBlue.onclick = themeBlueFunct; function themeBlueFunct (){ a.style.color = "blue"; } по клику должен поменяется цвет, но не меняется. |
Сергей Ракипов,
что такое a? Цитата:
|
Цитата:
let a = document.getElementsByTagName("a"); let themeBlue = document.querySelector("#theme_blue"); let theme = document.querySelector(".theme"); themeBlue.onclick = themeBlueFunct; function themeBlueFunct (){ a.style.color = "blue"; } забыл дописать вот так было |
Цитата:
a[0].style.color = "blue"; |
Цитата:
|
Цитата:
|
Цитата:
и делаю так let themeGreen = document.querySelector("#theme_green"); let theme = document.querySelectorAll(".theme"); themeGreen.onclick =themeGreenFunct; function themeGreenFunct (){ theme.style.color = "green"; } в css класс .theme присутствует но все равно не срабатывает |
Цитата:
Цитата:
Цитата:
|
Цитата:
Просто я думал что querySelector возьмет первый А querySelectorAll пройдется по всем как то не логично. А как цикл написать что бы он прошелся по всем элементам |
Так пробую, не получается
function themeGreenFunct (){ for(i=0; i<theme.length; i++){ theme.style.color = "green"; } } |
Сергей Ракипов,
theme[i].style.color = "green"; function themeGreenFunct (){ let theme = document.querySelectorAll(".theme"); for(let i=0; i<theme.length; i++){ theme[i].style.color = "green"; } } |
Отлично все сработало, спасибо :)
|
Часовой пояс GMT +3, время: 00:28. |