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

Question #302709

DOM Manipulations

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

Use the below reference image.

https://assets.ccbp.in/frontend/content/dynamic-webapps/ce-3-1-2-dom-manipulations-op.png


HTML

<!DOCTYPE html>

<html>


<head></head>


<body>

  <div id="interestsContainer"></div>

</body>


</html>


Dynamically add the

input elements in HTML container element with id interestsContainer to achieve the design.

Note

  • For one input use the htmlFor property to add HTML for attribute.
  • For other input use the setAttribute method to set the HTML attribute for.
1
Expert's answer
2022-02-28T08:31:09-0500
<!DOCTYPE html>
<html>
<head></head>
<body>
    <div id="interestsContainer"></div>
    <script>
        const container = document.querySelector('#interestsContainer');

        const title = document.createElement('h1'),
              music = document.createElement('input'),
              dance = document.createElement('input'),
              musicTitle = document.createElement('label'),
              danceTitle = document.createElement('label');

        title.innerHTML = 'Choose your interests'
        container.append(title)

        music.type = 'checkbox';
        dance.setAttribute('type', 'checkbox');

        musicTitle.innerHTML = 'Music';
        danceTitle.innerHTML = 'Dance';

        container.append(music);
        container.append(musicTitle)
        container.append(dance)
        container.append(danceTitle)

    </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