Jump to content

How to: document.querySelectorAll(p , div) ?


vmars316
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...