Jump to content

Explain example please?


eduard
 Share

Recommended Posts

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

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 by niche
Link to comment
Share on other sites

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

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 by eduardlid
Link to comment
Share on other sites

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

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

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

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

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 by eduardlid
Link to comment
Share on other sites

The value of an id I set p s no copy and paste
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.

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...