Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to use document.querySelector() in javascript

Avatar

Avatar
Validate 1
Level 1
ShagunMalik
Level 1

Like

1 like

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
Ignite 1
Give Back
View profile

Avatar
Validate 1
Level 1
ShagunMalik
Level 1

Like

1 like

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
Ignite 1
Give Back
View profile
ShagunMalik
Level 1

20-04-2021

I'm trying to use document.querySelector() in javascript.

There is a element in my html with 'ul' tag.

then in my javascript I'm using it as :

const ultag = document.querySelector("ul");

then I'm calling a function for pagination like :

function x(pagecount,currentpage)

{

let litag =' ';

if (page<1)

{

litag= something;

}

ultag.innerHTMl = litag;

}

but it is showing error in ultag.innerHTML as it is showing null value for ultag.

Please help how to use it.

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

367 likes

Total Posts

462 posts

Correct Reply

134 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

367 likes

Total Posts

462 posts

Correct Reply

134 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile
asutosh_jena
Level 10

20-04-2021

Hi @ShagunMalik 

 

Let's say you have the HTML markup as:

 

<ul class="project-list single-col">
<li class="project-item" style="clear: left;">
Something
</li>
<li class="project-item" style="clear: left;">
Something
</li>
<li class="project-item" style="clear: left;">
Something
</li>
</ul>

 

In JS If you use the below code:

var x = document.querySelector("ul");

 x will hold the complete markup that we have above.

 

Thanks!

Answers (1)

Answers (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

20-04-2021

@ShagunMalik 

Are you sure you have at-least one ul tag in page? If there is no ul tag in DOM, document.querySelector("..") will return null.