eduard Posted June 18, 2012 Share Posted June 18, 2012 Can anybody explain this example please? var carname="Volvo";document.getElementById("myP").innerHTML=carname; I don´t understand "myP"? Link to comment Share on other sites More sharing options...
niche Posted June 18, 2012 Share Posted June 18, 2012 (edited) not surprisingly, getElementById("myP") is referring to an id. your code is changing the value of the html, in the id, to the value of the variable. EDIT: here's a ref for ids:http://www.w3schools...ss_id_class.asp Edited June 18, 2012 by niche Link to comment Share on other sites More sharing options...
thescientist Posted June 18, 2012 Share Posted June 18, 2012 have you looked up the method document.getElementById to see what it does? Aside from the very obvious intent in the method name, "myP" is the name of the element you want to reference with this method.http://www.w3schools.com/jsref/met_doc_getelementbyid.asp You should know what an ID is from the numerous questions you've asked in the HTML/CSS forums. Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 (edited) have you looked up the method document.getElementById to see what it does? Aside from the very obvious intent in the method name, "myP" is the name of the element you want to reference with this method.http://www.w3schools...elementbyid.asp You should know what an ID is from the numerous questions you've asked in the HTML/CSS forums. I know what id and class are, but I don´t undetstand the examples well! myP is an id (html)Volvo is a value (JS)? Edited June 18, 2012 by eduardlid Link to comment Share on other sites More sharing options...
boen_robot Posted June 18, 2012 Share Posted June 18, 2012 I know what id and class are, but I don´t undetstand the examples well!Khm... I've asked you before, and I'll ask you again. And I hope you're now ready to prove you know this, by answering the following question:Is the value of a class (or ID) something you define or something HTML asks of you?Don't be the food thief! Cooperate! Link to comment Share on other sites More sharing options...
justsomeguy Posted June 18, 2012 Share Posted June 18, 2012 Khm... I've asked you before, and I'll ask you again. And I hope you're now ready to prove you know this, by answering the following question:Some say that the definition of insanity is repeatedly doing the same thing and expecting different results. Link to comment Share on other sites More sharing options...
boen_robot Posted June 18, 2012 Share Posted June 18, 2012 Some say that the definition of insanity is repeatedly doing the same thing and expecting different results.Oh... but I believe things have changed in a way (the "food thief" reference was not applicable until very recently) . Now if only Eduard sees through it, we may have progress. Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 Khm... I've asked you before, and I'll ask you again. And I hope you're now ready to prove you know this, by answering the following question: Is the value of a class (or ID) something you define or something HTML asks of you? Don't be the food thief! Cooperate! I hope this will do:The value of an id I set p s no copy and paste Link to comment Share on other sites More sharing options...
eTianbun Posted June 18, 2012 Share Posted June 18, 2012 Just Go through the Javascript tutorial @w3schools, and i believe they explained everything there. Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 (edited) Just Go through the Javascript tutorial @w3schools, and i believe they explained everything there. What do you think I´m doing? p s I believe ..... is NOT me Edited June 18, 2012 by eduardlid Link to comment Share on other sites More sharing options...
eTianbun Posted June 18, 2012 Share Posted June 18, 2012 What do you think I'm doing? It seems you are not reading it. Link to comment Share on other sites More sharing options...
boen_robot Posted June 19, 2012 Share Posted June 19, 2012 The value of an id I set p s no copy and pasteTHERE! This is what I wanted to see all along. Was it that hard? Did we had to go over all the drama?Anyway... now that we have that covered... see the code again:document.getElementById("myP") getElementById wants you to specify the value of an ID, and then it gets the element with that ID. Like you said, the value of an ID is something you set.So: "myP" is simply the value of an ID that someone chose to specify. For this code to work, somewhere in the HTML document, there needs to be an element with "myP" as its ID. If you don't have an element with such an ID, you can change "myP" into the ID of another element that you do have. Link to comment Share on other sites More sharing options...
eduard Posted June 19, 2012 Author Share Posted June 19, 2012 THERE! This is what I wanted to see all along. Was it that hard? Did we had to go over all the drama? Anyway... now that we have that covered... see the code again:document.getElementById("myP") getElementById wants you to specify the value of an ID, and then it gets the element with that ID. Like you said, the value of an ID is something you set. So: "myP" is simply the value of an ID that someone chose to specify. For this code to work, somewhere in the HTML document, there needs to be an element with "myP" as its ID. If you don't have an element with such an ID, you can change "myP" into the ID of another element that you do have. Ok, many thanksp s I wrote that my circumstances have changed - no thief Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now