Basic JavaScript output and embedded writing tutorials, javascript embedded

Source: Internet
Author: User

Basic JavaScript output and embedded writing tutorials, javascript embedded

JavaScript does not have any printing or output functions.
In HTML, JavaScript is usually used to operate HTML elements.
Operate HTML elements
To access an HTML element from JavaScript, you can use the document. getElementById (id) method.
Use the "id" attribute to identify HTML elements and innerHTML to obtain or insert element content:
Instance

<! DOCTYPE html> <body> 

The preceding JavaScript statement (in the <script> tag) can be executed in a web browser:

  • Document. getElementById ("demo") is the JavaScript code that uses the id attribute to search for HTML elements.
  • InnerHTML = "Paragraph changed." Is the JavaScript code used to modify the HTML content (innerHTML) of an element.

Write to HTML document
For testing purposes, you can write JavaScript directly in HTML documents:
Instance

<! DOCTYPE html> <body> 

Use document. write () to output only the written content to the document.
If you execute document. write after the document has been loaded, the entire HTML page will be overwritten.
Instance

<! DOCTYPE html> <body> 

Write to console
If your browser supports debugging, you can use console. log () to display JavaScript values in your browser.
Use F12 in the browser to enable the debugging mode. In the debugging window, click the "Console" menu.
Instance

<! DOCTYPE html> <body> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.