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

Getting error "Cannot set property 'innerHTML' of undefined"

Avatar

Avatar
Validate 1
Level 1
ShagunMalik
Level 1

Like

1 like

Total Posts

55 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

55 posts

Correct Reply

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

08-04-2021

Whenever i'm trying to access data of <p> tag using getElementById in js, then the data is getting accessed but when i try to change the content of <p> tag in js using .innerHTML, I'm getting error UnCaught TypeError:Cannot set property 'innerHTML' of undefined.

How can it be resolved.

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 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

275 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

08-04-2021

@ShagunMalik 

HTML

 

<p id="my-id"> </p>

 

Using Vanilla JavaScript

 

document.getElementById("my-id").innerHTML = "Some text";

 

Using jQuery

 

$("#my-id").text("Some text");

 

 

 

 

Answers (0)