Skip to content

#22 πŸ›‘ DOM Selectors And Selectors Functions

Adarsh Tripathi edited this page Jul 30, 2021 · 2 revisions
*****************************Tutorial Start πŸ”₯ ********************************

DOM Selectors and Selectors functions

<h2 id="banrid">Hello World</h2>
<h3 class="headingClass">This is javScript</h3>
<h3 class="headingClass">This is javScript</h3>
<h3 class="headingClass">This is javScript</h3>
<!-- get element by tag name-->

<p>Example 1: Some Text</p>
<p>Example 2: Some Text</p>
<button onclick="getTagNameParams();">Show all p elements in the document</button>

<!-- get element by query selector-->
<h4 class="reactHeading">This is React</h4>
<h4 class="reactHeading">This is React</h4>
<h4 class="reactHeading">This is React</h4>

selecting element by using id with getElementById() function

particular element selectors like h1, p , span, ul li, and many more by using id

agar kisi bhi elements ko select karna hai using ID too use karege getElementById() function

getElementById() --> return karega single object, kyu ki id kisi bhi page ki unique hoti hai, aur single element return karna hai aik hi isliye hum Element use karege not Elements

jab bhi humko kisi element ko select karna hai by id too hum use karege getElementById() not getElementsById()

agar aik variable bhut saare elements hogye too voo aik array ban jaati hai.

and array ko traverse karne ke liye hum for..of loop use kar sakte hai.

hum css selectors bhi use kar sakte hai elements ko select karne ke liye.

    There are 2 function we use to do this: 1. querySelector() -->ye single element return karega, pehla element
    return kar dega
    2. querySelectorAll() --> ye list of element return karega, jitne bhi element match karge
    selectors se usko return kar dega.

css selector use karne ke liye . lagana padhta hai

querySelector()--> bus 1 element return karega

querySelectorAll()-->ye list of element ke object ko return karega nodelist me and fhir hum loop laga sakte hai

***************************** Tutorial End πŸš€ ********************************
Clone this wiki locally