简体   繁体   中英

Can someone tell me if I am right in my explanation of HTML/JS code?

I am trying to explain lines of code to my class as part of homework, I explained them like this, yet I am not sure I am 100% right. I have to be 100% accurate by the way I am marked on how detailed and accurate I am.

<!DOCTYPE html> 

The first command tells the computer that the document type (DOCTYPE) is html

   <html> 

is used to identify the document as an html (web) document should be the last command as it ends the script.

<body> 

The body is the section in which the main content of the page is placed. All text, links, and image references must be placed within the body section.

 <h1>Change an HTML element</h1>

h1 stands for heading 1 and is the main heading of the html, “Change an HTML element”.

<p id="msg">Now you see me.</p>

p is stands for paragraph and it is the main text where the code will show up. Id="msg" gives the text “Now you see me” an identification (almost like a variable in python) so “Now you see me” = "msg"

<button type="button" 

Decides what type of button it is and what will go into the button.

onclick="document.getElementById('msg').innerHTML = 'Gone!'"> 

When the button is clicked (“onclick”) it goes into the html document and gets the element by “id” and the id is msg and “msg” is changed to “Gone!”, msg was previously “Now you see me”.

   Click me!</button> 

This is basically the text that goes into the button, the button will be called “Click me!” the “/” ends the button so that's all it does once clicked it changes msg to “Gone!”.

You are basically right here. However a few notes:

your <p id="msg">Now you see me.</p> tag description is a bit ambiguous. The id itself does not specify what goes inside the tag. It gives the tag an identifier so it can be uniquely referenced later and "now you see me" doesnt exactly mean "msg". The tag with the Id="msg" has a value of "Now you see me."

<h1> doesnt necessarily mean it's the first heading. It specifies the size of the heading denoting importance or nesting. is the outer most heading and therefore the largest of all heading 1-6.

onclick is mostly right however "msg" isnt changed to "Gone!", the innerHTML (the value of the element) is changed to "Gone!". "msg" is just the unique identifier for that element as I described above.

"/" in </button> doesn't mean that it will change the content of any element, it is just the closing tag, telling the HTML parser that the button tag has ended and it should have all the info it needs to create the button element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM