Author: ShairyPortfolio

  • Task Using Traversing Elements in DOM

    Task Using Traversing Elements in DOM

    Task 1 : In the below task find all the next sibling of “spl” id H1 Tag  <div id=”demo”>                 <h1>This is Heading 1</h1>                 <h1 id=”spl”>This is Heading 1</h1>                 <h2>This is a Heading 2</h2>                 <h2>This is a Heading 2</h2>                 <h2>This is a Heading 2</h2>                 </div> Solution of Task 1   …

  • Traversing Elements in DOM

    Traversing Elements in DOM

    Get the parent element – get the parent node of an element. Get child elements – get children of an element. Get siblings of an element – get siblings of an element. Get the parent element             Syntax             let parent = node.parentNode;             Example             <body>                          <div class=”demo”>                                     <p class=”par”>This…

  • Task using Selecting Elements in Dom
  • Selecting Elements in DOM

    Selecting Elements in DOM

    getElementById() – select an element by id. getElementsByName() – select elements by name. getElementsByTagName() – select elements by a tag name. getElementsByClassName() – select elements by one or more class names. querySelector() and querySelectorAll – select elements by CSS selectors. Note that the getElementById() and querySelector() returns an object with the Element type while getElementsByTagName()…