+ 2

I want to take name from user and convey birthday wishes..

Javascript https://code.sololearn.com/WkRf2rzs0Cx2/?ref=app

13th Jun 2020, 2:36 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
4 odpowiedzi
+ 1
window.onload=function(){ var x =prompt("Enter your name"); var f=document.createTextNode(x); document.getElementsByClassName("takefromuser")[0].appendChild(f); } You should read about how getElementsByClassName works ,it returns an array of all the classes with same name so to actually access the element you need to call it by index like [0] or [1] like you would do with an array And window.onload function tells browser to load JavaScript only after html document is loaded otherwise undefined errors will be thrown
13th Jun 2020, 2:47 PM
Abhay
Abhay - avatar
+ 1
👍
13th Jun 2020, 3:20 PM
Abhay
Abhay - avatar
+ 1
Mustafha Ahmad Instead do it this way window.onload=function(){ var x =prompt("Enter your name"); document.getElementsByClassName("takefromuser")[0].innerHTML=x; }
13th Jun 2020, 3:21 PM
Abhay
Abhay - avatar
0
Thank you
13th Jun 2020, 3:18 PM
Mustafha Ahmad
Mustafha Ahmad - avatar