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

Question #302686

Remove and Add Class Names

The goal of this coding exam is to quickly get you off the ground with Adding and Removing Classnames Dynamically.

Use the below reference linkimage.

https://assets.ccbp.in/frontend/content/dynamic-webapps/adding-and-removing-classnames-dynamically-op.gif


HTML

<!DOCTYPE html>

<html>


<head></head>


<body>

  <h1 class="heading-old-styles" id="heading">h1 Element</h1>

  <button id="btnEl" class="button">Remove old styles and add new styles</button>

</body>


</html>


CSS

.heading-old-styles {

  color: #00ff00;

  background-color: #000000;

}


.button {

  color: #ffffff;

  background-color: #0967d2;

  font-size: 14px;

  border-width: 0;

  border-radius: 4px;

  padding: 10px;

}


.heading-new-styles {

  color: #ff0000;

  background-color: #ffffff;

}




1
Expert's answer
2022-02-25T10:29:15-0500
<!DOCTYPE html>
<html>
<head></head>
<body>
    <style>
        .heading-old-styles {
        color: #00ff00;
        background-color: #000000;
        }
        .button {
            color: #ffffff;
            background-color: #0967d2;
            font-size: 14px;
            border-width: 0;
            border-radius: 4px;
            padding: 10px;
        }
        .heading-new-styles {
            color: #ff0000;
            background-color: #ffffff;
        }
    </style>
    <h1 class="heading-old-styles" id="heading">h1 Element</h1>
    <button id="btnEl" class="button">Remove old styles and add new styles</button>
    <script>
        const heading = document.querySelector('#heading'),
              btn = document.querySelector('#btnEl');

        btn.addEventListener('click', () => {
            heading.classList.toggle('heading-old-styles')
            heading.classList.toggle('heading-new-styles')
        })
    </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