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

SOLVED

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

ShagunMalik
Level 3
Level 3

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.

 

1 Accepted Solution
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

@ShagunMalik 

HTML

 

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

 

Using Vanilla JavaScript

 

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

 

Using jQuery

 

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

 

 

 

 

View solution in original post

1 Reply
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

@ShagunMalik 

HTML

 

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

 

Using Vanilla JavaScript

 

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

 

Using jQuery

 

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

 

 

 

 

View solution in original post