The Section object represents an HTML <section> element.
We can access a <section> element via document.getElementById()
:
var x = document.getElementById("mySection");
Click the button to set the text color of the section content to red.
<!DOCTYPE html> <html> <body> <section id="mySection"> <h1>Section Heading</h1> <p>Some text in section..</p> </section>/*from ww w .ja v a 2 s .c om*/ <button onclick="myFunction()">Test</button> <script> function myFunction() { var x = document.getElementById("mySection"); x.style.color = "red"; } </script> </body> </html>