DOM element manipulation in JavaScript

Source: Internet
Author: User
Tags tag name

DOM Event actions in JavaScript

    • Function

    • The function is to encapsulate some methods by calling the Execute function.
    • Role:
      • Avoid repeating the code.
      • Simplify programming and make programming modular.
    • Syntax: Fuction () {}
      • function is a keyword, similar to the "def" of a function defined in Python;
      • Enclose parameters in parentheses
      • A function statement is placed in curly braces.
    • Call to function
      • Function name + ()
    • parameters of the function
      • parameter
      • argument
    • Argument: can only be used in functions.
      • Number of returned arguments: argument.length
      • Returns the number of formal parameters: Fn.length
      • Pseudo-Array
        • You can modify the element, but you cannot change the length of the array. (Use only the array method)              

          • Empty array
            1. Array.splici (0)
            2. Array.Length = 0
            3. Array = []

    • DOM Event action
      • JS is an event-driven core language.

      • Event three elements:  
        • Event Source: HTML tag that raises subsequent events
        • Event: a drive action
        • Event driver: An action on a style or HTML.

      • Event writing steps

      • Gets the event source.
        1. Get a single tag by ID :getElementById ("ID name") must be quoted and element has no s.
        2. Get an array of tags by tag name : getElementsByTagName ("tag name"), Elenment has s,
        3. Get label Group BY class name:getelementsbyclassname ("Class name")Elenment has s,  
      • The binding event.
          1. Directly binds an anonymous function.
          2. Define the function first, and then bind the encapsulated function body.
            • Note: The binding is FN, not FN (), and FN () refers to the function's return value.   
          3. In-line methods.
            • inline style, when you write FN (), you must have parentheses at this point, otherwise parse to a string .

                    

      • Write event drivers. Operations on the DOM

          • Notes for writing code:
            1. When writing attribute values in JS, use quotation marks.
            2. When writing attributes in JS, write a camel's body, such as backgroundcolor.        

DOM element manipulation in JavaScript

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.