Learn the JavaScript classList property easy! 💡

  Рет қаралды 12,910

Bro Code

Bro Code

Күн бұрын

Пікірлер: 17
@BroCodez
@BroCodez Жыл бұрын
// classList = Element property in JavaScript used to interact // with an element's list of classes (CSS classes) // Allows you to make reusable classes for many elements // across your webpage. // add() // remove() // toggle(Remove if present, Add if not) // replace(oldClass, newClass) // contains() // ---------- button ---------- const myButton = document.getElementById("myButton"); myButton.classList.add("enabled"); myButton.addEventListener('mouseover', event => { event.target.classList.toggle('hover'); }); myButton.addEventListener('mouseout', event => { event.target.classList.toggle('hover'); }); myButton.addEventListener('click', event => { if(event.target.classList.contains("disabled")){ event.target.textContent += "🤬"; } else{ event.target.classList.replace("enabled", "disabled"); } }); // ---------- h1 ---------- const myH1 = document.getElementById("myH1"); myH1.classList.add("enabled"); myH1.addEventListener("mouseover", event => { event.target.classList.toggle('hover'); }); myH1.addEventListener('mouseout', event => { event.target.classList.toggle('hover'); }); myH1.addEventListener('click', event => { if(event.target.classList.contains("disabled")){ event.target.textContent += "🤬"; } else{ event.target.classList.replace("enabled", "disabled"); } }); // ---------- NodeList ---------- let buttons = document.querySelectorAll(".myButtons"); buttons.forEach(button => { button.classList.add("enabled"); }); buttons.forEach(button => { button.addEventListener("mouseover", event => { event.target.classList.toggle("hover"); }); }); buttons.forEach(button => { button.addEventListener("mouseout", event => { event.target.classList.toggle("hover"); }); }); buttons.forEach(button => { button.addEventListener("click", event => { if(event.target.classList.contains("disabled")){ event.target.textContent += "🤬"; } else{ event.target.classList.replace("enabled", "disabled"); } }); }); Document Hello My button Button 1 Button 2 Button 3 Button 4 #myH1{ font-size: 5rem; } #myButton, .myButtons{ font-size: 4rem; margin: 10px; border: none; border-radius: 5px; padding: 10px 15px; } .enabled{ background-color: hsl(204, 100%, 50%); color: white; } .hover{ box-shadow: 0 0 10px hsla(0, 0%, 0%, 0.2); font-weight: bold; } .disabled{ background-color: hsl(0, 0%, 60%); color: hsl(0, 0%, 80%); }
@salad333
@salad333 Жыл бұрын
is there any way to contact you for asking questions about programming language? like discord, facebook something like that? 😃
@uncannypotato6952
@uncannypotato6952 Жыл бұрын
hi man. i am enjoying your tutorials. the tut are very easy to understand (just completed the 5th one). thanks
@widespectrumcreators4691
@widespectrumcreators4691 Жыл бұрын
BroCode best tutorials!! 👍👍😀🤩🤩
@famero_xo
@famero_xo 6 ай бұрын
Best tutorial 🎉❤
@felipenogueira7518
@felipenogueira7518 Жыл бұрын
Great, bro. Thank you very much!
@777etr6
@777etr6 4 ай бұрын
amazing
@کوروشبصیری
@کوروشبصیری Жыл бұрын
King❤❤
@msamer55
@msamer55 4 ай бұрын
hey there: if anyone faces the error of chrome not applying the Background color property from .enabled class in css try using this syntax: background-color: hsla(41, 61%, 50%, 0.829) *!important*;
@raoufsnowden2988
@raoufsnowden2988 2 ай бұрын
thank you sir 🙏
@Elninooooooooo
@Elninooooooooo Жыл бұрын
Hello my friend from Vietnam. Let me ask, how long does it take us to master a programming language?
@SyefTheCandJavaCoder
@SyefTheCandJavaCoder 6 ай бұрын
A year or months
@DySun
@DySun 4 ай бұрын
depends on the programming language. For JavaScript, learning all the syntax takes less than a month. But to be conversant with the language requires many more months (even years) of actual hands-on doing real projects.
@ozairabtahi
@ozairabtahi 11 ай бұрын
bro what did you click on keyboard to access the emoji???????????????
@ivvy2730
@ivvy2730 11 ай бұрын
windows + .
@abdeSaves
@abdeSaves 7 ай бұрын
windows + ;
@hamzagohar2048
@hamzagohar2048 5 ай бұрын
seems like you did not watched the whole playlist
Build JavaScript ROCK PAPER SCISSORS in 18 minutes! 👊
18:54
What are NodeLists in JavaScript? 📃
13:22
Bro Code
Рет қаралды 10 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
Learn JavaScript ELEMENT SELECTORS easy! 📑
17:38
Bro Code
Рет қаралды 31 М.
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
Learn DOM Manipulation In 18 Minutes
18:37
Web Dev Simplified
Рет қаралды 1 МЛН
Learn DOM Navigation in 15 minutes! 🧭
15:27
Bro Code
Рет қаралды 17 М.
Object-oriented Programming in JavaScript: Made Super Simple | Mosh
1:02:49
Programming with Mosh
Рет қаралды 2 МЛН
Learn JavaScript CALLBACKS in 7 minutes! 🤙
7:17
Bro Code
Рет қаралды 71 М.
JavaScript GETTERS & SETTERS are awesome!!! 📐
13:14
Bro Code
Рет қаралды 20 М.
Build a JavaScript IMAGE SLIDER in 15 minutes! 🖼️
15:49
Bro Code
Рет қаралды 59 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23