Jump to content

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


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...