vmars316 Posted October 24, 2020 Report Share Posted October 24, 2020 Tia ; I want to change all fontWeight of <p and <div>> to bold . <!DOCTYPE html> <html> <head> <title>Bold Text Demo</title> </head> <body> <p> This is a sample paragraph </p> <button id="button"> Make Bold </button> <div>This is a sample div</div> <script> //Get the button element var btn = document.getElementById('button'); //Get paragraph element var makeBold = document.querySelectorAll(p , div); //Define an click event listener on button btn.addEventListener('click', function() { //Change the font weight style to 700 makeBold.style.fontWeight = '700'; }); </script> </body> </html> How can I do that ? Thanks for your Help... Link to comment Share on other sites More sharing options...
dsonesuk Posted October 25, 2020 Report Share Posted October 25, 2020 (edited) Wrap in quotes 'p, div', then use for loop with makeBold.length to loop through collection from querySelectorAll(); to apply required style. Edited October 25, 2020 by dsonesuk 1 Link to comment Share on other sites More sharing options...
vmars316 Posted October 25, 2020 Author Report Share Posted October 25, 2020 Thanks dsonesuk ; Like this: Quote <script> //Get the button element var btn = document.getElementById('button'); //Get paragraph element var makeBold = document.querySelectorAll('p , div'); //Define an click event listener on button btn.addEventListener('click', function() { for (i = 0; i < makeBold.length; i++) { makeBold[i].style.fontWeight = '700'; } }); </script> Thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now