55author : " bbauska"
66date created : " 05/12/25 Mon 12+pm"
77date last editted : " 05/12/25 Mon 8+pm"
8+ date last editted : " 05/13/25 Tue 9+pm"
89output :
910 markdown :
1011 with some style
@@ -350,7 +351,7 @@ element.classList.add("className")
350351<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
351352<h3 >Using <b ><mark >className</mark ></b > Property</h3 >
352353<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
353- In this approach, we are using the <b ><mark >clasName </mark ></b > property. This property returns the
354+ In this approach, we are using the <b ><mark >className </mark ></b > property. This property returns the
354355<b ><mark >className</mark ></b > of the element. If the element has already a class then it will simply
355356add another one to it or else it will append our new class to it.
356357<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -414,28 +415,27 @@ add another one to it or else it will append our new class to it.
414415<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
415416<h2 >How to select DOM Elements in JavaScript?</h2 >
416417<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
417- Selecting <b ><mark >DOM (Document Object Model)</mark ></b > elements is a fundamental aspect of web
418+ < p > Selecting <b ><mark >DOM (Document Object Model)</mark ></b > elements is a fundamental aspect of web
418419development with JavaScript. It allows developers to interact with and manipulate elements
419420on a webpage dynamically. Proper selection of elements is crucial for tasks such as updating
420- content, adding event listeners, or modifying styles.
421+ content, adding event listeners, or modifying styles.</ p >
421422
422- Below are the approaches to select DOM elements in JavaScript:
423+ < p > Below are the approaches to select DOM elements in JavaScript:</ p >
423424
424425<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
425426<h4 >Table of Content</h4 >
426427<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
427428<ul >
428- <li >Using <b ><mark >getElementById</mark ></b ></li >
429- <li >Using <b ><mark >getElementsByClassName</mark ></b ></li >
430- <li >Using <b ><mark >getElementsByTagName</mark ></b ></li >
431- <li >Using <b ><mark >querySelector</mark ></b ></li >
432- <li >Using <b ><mark >querySelectorAll</mark ></b ></li >
429+ <li >< href id = " #01 " >1. Using <b ><mark >getElementById</mark ></b ></ a ></li >
430+ <li >< href id = " #02 " >2. Using <b ><mark >getElementsByClassName</mark ></b ></ a ></li >
431+ <li >< href id = " #03 " >3. Using <b ><mark >getElementsByTagName</mark ></b ></ a ></li >
432+ <li >< href id = " #04 " >4. Using <b ><mark >querySelector</mark ></b ></ a ></li >
433+ <li >< href id = " #05 " >5. Using <b ><mark >querySelectorAll</mark ></b ></ a ></li >
433434</ul >
434435<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
435- <h3 > Using <b ><mark >getElementById</mark ></b ></h3 >
436+ <h3 id = " 01 " >1. Using <b ><mark >getElementById</mark ></b ></h3 >
436437<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
437- This method selects a single element by its unique ID attribute.
438-
438+ <p >This method selects a single element by its unique ID attribute.</p >
439439<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
440440<h4 >Syntax:</h4 >
441441<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -471,7 +471,7 @@ This method selects a single element by its unique ID attribute.
471471<h4 >Output:</h4 >
472472<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
473473<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
474- <!-- ~~~~~~~~~~~~~~~~~~~~~~~ 05. ~~~~~~~~~~~~~~~~-->
474+ <!-- ~~~~~~~~~~~~~~~~~~~~~~~ 05. GeeksForGeeks in green ~~~~~~~~~~~~~~~~-->
475475<p align =" center " >
476476<a href=""
477477 target="_ blank" rel="noopener noreferrer">
@@ -485,7 +485,7 @@ This method selects a single element by its unique ID attribute.
485485</p >
486486<!-- image005.png -->
487487<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
488- <h3 > Using <b ><mark >getElementsByClassName</mark ></b ></h3 >
488+ <h3 id = " 02 " >2. Using <b ><mark >getElementsByClassName</mark ></b ></h3 >
489489<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
490490<p >This method selects elements based on their class attribute. It returns a collection of elements
491491with the specified class name.</p >
@@ -540,7 +540,7 @@ with the specified class name.</p>
540540</p >
541541<!-- image006.png -->
542542<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
543- <h3 > Using <b ><mark >getElementsByTagName</mark ></b ></h3 >
543+ <h3 id = " 03 " >03. Using <b ><mark >getElementsByTagName</mark ></b ></h3 >
544544<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
545545<p >This method selects elements based on their tag name. It returns a collection of elements with the
546546specified tag name.</p >
@@ -595,7 +595,7 @@ specified tag name.</p>
595595</p >
596596<!-- image007.png -->
597597<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
598- <h3 > Using querySelector</h3 >
598+ <h3 id = " 04 " >04. Using querySelector</h3 >
599599<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
600600<p >This method selects the first element that matches a specified CSS selector. It returns only
601601one element.</p >
@@ -649,7 +649,7 @@ one element.</p>
649649</p >
650650<!-- image008.png -->
651651<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
652- <h3 > Using querySelectorAll</h3 >
652+ <h3 id = " 05 " >05. Using querySelectorAll</h3 >
653653<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
654654<p >Similar to <b ><mark >querySelector</mark ></b >, but it returns a <b ><mark >NodeList</mark ></b > containing
655655all elements that match the specified CSS selector.</p >
0 commit comments