Answer to Question #302710 in HTML/JavaScript Web Application for chethan

Question #302710

DOM Manipulations - 2

The goal of this coding exam is to quickly get you off the ground with the DOM Manipulations.

Use the below reference image.

https://res.cloudinary.com/dfxicv9iv/image/upload/v1619259911/dom-manipulations-2_ax38mg.gif

HTML

<!DOCTYPE html>

<html>


<head></head>


<body>

  <div id="myContainer"></div>

</body>


</html>


Dynamically add the elements in HTML container element with id

myContainer to achieve the design.

Note

Use the checked property and classList.toggle method to achieve the functionality.

Resources

CSS Colors used:

#7a0ecc

#f2ebfe





1
Expert's answer
2022-02-28T08:31:05-0500
<!DOCTYPE html>
<html>
<head></head>
<body>
    <style>
        .active {
            color: #7a0ecc;
            background: #f2ebfe;
        }
    </style>
    <div id="myContainer"></div>
    <script>
        const container = document.querySelector('#myContainer');

        const check = document.createElement('input'),
              checkTitle = document.createElement('label'),
              heading = document.createElement('h1');

        check.type = 'checkbox';
        checkTitle.innerHTML = 'Color the heading element';
        heading.innerHTML = 'heading Element';

        container.append(check, checkTitle, heading)

        check.addEventListener('change', () => {
            if (check.checked == false)
                checkTitle.innerHTML = 'Color the heading element';
            else
                checkTitle.innerHTML = 'Uncolor the heading element';
            heading.classList.toggle('active')
            
        });
    </script>
</body>
</html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS