document.getElementsByClassName() example
RUN
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> #result{ color: red; font-size: 20px; font-weight: bold; } </style> <body> <h1>Học lập trình miễn phí tại freetuts.net</h1> <ul class="freetut"> <h3>Khóa học 1</h3> <h3 class="demo"> Name: PHP</h3> <h3 class="demo">Time: 48 Videos</h3> <h3 class="demo">Author: Nguyễn Văn A</h3> </ul> <p id="result"></p> <button onclick="myFunction()">Xem kết quả</button> <script> function myFunction(){ var NodeObject = document.getElementsByClassName("demo"); NodeObject[0].style.color = "red"; NodeObject[1].style.color = "blue"; NodeObject[2].style.color = "yellow"; } </script> </body> </html>
PHÓNG TO