What's wrong with my code in HTML
script elements may also be noted within flow elements.
Attributes in the element 
- In HTML5 you can omit the specification of the MIME type - in older HTML variants this specification is necessary.
- The language attribute was classified as deprecated and must be omitted.
It used to be common to enclose scripts in a CDATA block. The need for this only existed for XHTML documents, but was understood by many as “this is how it must be” and used everywhere. It didn't bother either. There is also an XML notation for HTML 5, but as long as you do not want to process such a document with an XML tool, the CDATA notation is no longer necessary.
In the last 2 lines, the button is accessed with the id and assigned to it via the event handler. A click on the button calls up the function.In order for this event handler to be assigned, the element must already exist. Therefore, the script should either be called at the end of the HTML document or after the final loading of the page (using) a function.
The src-Attribute (source = "Source") has the URI to the script as its value. (More information about referencing in HTML)
Script in the head or at the end of the body element? [Edit]
A question that is asked again and again is which of the two positions is better.
When a browser loads a web page, it follows a fixed routine:
- The browser fetches the HTML file
- The HTML markup is parsed
- The browser sends a request that the script should be loaded. In the meantime, the parsing of the rest of the HTML markup will be stopped.
- After a while, the script will be downloaded and executed.
- The browser continues parsing the rest of the HTML.
Why is there an interruption in step 4? Scripts can insert or change HTML with document.write () or other DOM manipulations. So the parser waits for the script to download and run before parsing the rest of the document.
So scripts should be loaded as soon as possible.
Conclusion: in the head
You can use the async and defer attributes to tell the browser that it can continue parsing while it is downloading scripts.
Even on the few old browsers that do not yet support these attributes, your pages will load correctly.
However, when using async and defer you need to keep an eye on the browser's processing order.
Inline scripts without and external scripts that have no - or - attribute stop processing the HTML document and are executed as soon as they are encountered. In the case of external scripts, this can initially mean access to the server if they are not in the cache and cause a noticeable delay.
All other scripts are placed in a queue. If the script is external and not in the cache, the browser requests it from the server.
After the document has been loaded, processing of the queue begins. The scripts set with are processed strictly in the order in which they were set, regardless of the order in which the server delivered them. The event is only signaled after the last script.
The scripts set with are executed in the order in which they become available. This can be before the first script, between two scripts or after the last script.
- Scripts without or become always executed before the event. A handler for the event, which you register in a script, is definitely executed.
- The scripts are also running always before the event. A handler for the event that you register in such a script is definitely executed.
- A script can be executed before or after. A handler for the event is only executed if the script was available in good time. You can use the property of the object to determine in a script whether it has already triggered. If it contains the value, it is still to come, otherwise it is already over.
- But beware: An old browser, whether or not it supports it, loads the script when it encounters it and executes it immediately. Such browsers may also not support the property of the document, or Internet Explorer versions 9 and 10 can report an incorrect readyState. If you are dependent on the existence of DOM objects, try to find one in your script. If it is still missing, register your logic in a DOMContentLoaded handler.
Web links 
- What is the formulation of Dettol
- How do I choose the right urologist
- Why do people disable Facebook accounts
- How can I get a bank statement
- How do people buy shoes online
- What famous preachers are the best speakers
- Why are universities full of militant vegans
- RSS subscriptions are dead
- Overall, how many Bollywood actors are rich
- What are some of the reasons people like Toronto
- What are the properties of plastics
- All actions have moral consequences
- How much does a restaurant designer cost
- Did a nightmare ever save your life
- Why do baseball players wear belts
- Anything can be art
- What are TCS values
- Hotel prices change daily
- Why are we ourselves but not others
- Where is the Maris Hospital in Dubai located
- Who buys furniture
- What is underwater welding technology
- Is online marriage counseling and therapy effective
- How does a payroll card work
- Is it rude to ask someone for grades?
- What are the best Spencer Tracys movies
- Is Macau a communist country
- How hard is Goku's skin
- What is adequate compensation
- Schueler Navratna-Oil can be applied
- Britain is currently a matriarchal society
- How is borax different from boric acid
- How do you define a patriotic person