Task Using Selecting Attribute of DOM

Task Using Selecting Attribute of DOM

In the Below HTML Code task perform the following :
  • First select the button with the id send by using the querySelector() method.
  • Second, set the value of the name attribute to submit using the setAttribute() method. Then get the value of name attribute.
  • Third, Paragraph is align right in the given HTML; remove the align attribute so that paragraph set to left automatically
  • Fourth, Check align attribute exist or not
  • Last, As we know by default link is blue in color and underline, change into red color and remove the underline.

<body>

    <button id=”send”>Send</button>

                <p align=”right”> This is align right Paragraph</p>

                <a href=”http://google.com”>Google</a>

</body>

Solution

    <script>

        let send = document.querySelector(‘#send’);

                               console.log(send);

        send.setAttribute(‘name’, ‘submit’);

                                console.log(send);

        console.log(send.getAttribute(‘name’));

                                let paragraph = document.querySelector(‘p’);

                                console.log(paragraph);

                                paragraph.removeAttribute(‘align’);

                                console.log(paragraph);

                                console.log(paragraph.hasAttribute(‘align’));

                                let link = document.querySelector(‘a’);

                                link.style.color = ‘red’;

                                link.style.textDecoration = ‘none’;    

</script>

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*