Notes on JavaScript cultivation (2) JavaScript and Web

Source: Internet
Author: User

1) Get the DOM element ID and CSS attributes

Dom is the HTML node. Javascript operates these nodes to achieve website dynamics.

The original W3C also provides node access operations, but it is not very useful.

Direct access to ID nodes

$ ('# Elementid ')

2) Modify CSS attributes

The CSS attribute corresponds to a class in HTML. The value of each class must be consistent with a value in the CSS list so that the webpage can be correctly displayed. Javascript is used to modify the values of these classes, to dynamically change the website content.

Get Style

((Element).css ('prop ')

Modify Style

((Element).css ('prop', 'value ')

((Element).css ({prop: 'value', prop2: 'value2 '})

3) Common HTML operations

Update all elements

((Element).html ("<p> Hello </P> ")

$ (Element). Text ("<p> Hello </P> ")

Inject other content into the element

$ (Element). Before ("<p> Hello </P> ")

$ (Element). prepend ("<p> Hello </P> ")

$ (Element). append ("<p> Hello </P> ")

$ (Element). After ("<p> Hello </P> ")

4) Dom loading and window onload

It is generally considered that Dom loading is faster, but in some cases it is not loaded using Windows. For example, you need to wait until the image is loaded to know the size of the image.

In HTML:

<Body onload =" Sometriccriptcode">

In javascript:

Window. onload = function (){ Sometriccriptcode};

5) Listen to events

There are many events. jquery uses bind and unbind to listen to a certain element.

This part is not carefully read, but it is basically all about jquery. You need to carefully read the following jqeury-related content in the future.

Related Article

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.