jquery Objects and Dom objects

Source: Internet
Author: User


1. The relationship between jquery object and Dom object

Dom object, if you want to invoke the method of jquery, you must first convert to a jquery object

Dom Objects: objects in the document tree are DOM objects

jquery Object: wraps the DOM object and gets the jquery object


2. The conversion between the JQuery object and the DOM object


2.1. How to get DOM objects : jquery->dom

$ (spobj) [0].innerhtml

$ (spobj). Get (0). InnerHTML


2.2. How to convert a DOM object to a jquery object

$ (spobj)


3. How does jquery get the elements on the page?

The jquery object is acquired primarily by the following methods

$ (' #id ')

$ (' span ')

$ ('. CLS ')

Once acquired, it is a jquery object, and the jquery method can be called through the jquery object, for example

. Text ()

. Val ()

. html ()

. css (' color ', ' Red ');


Most of jquery is a method, with few attributes, because properties are difficult to Chain-program. Get the value, set the value to use the same method, the parameter represents the set value, no parameter represents the value


4. Example


4.1. use DOM object to change background color

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "http// WWW.W3.ORG/TR/HTML4/LOOSE.DTD ">

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/86/AA/wKioL1fG9GyBLQd1AACxJEjnruE525.gif "title=" Change _backgroundcolor.gif "alt=" wkiol1fg9gyblqd1aacxjejnrue525.gif "/>



4.2. use jquery objects to change the background color

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "http// WWW.W3.ORG/TR/HTML4/LOOSE.DTD ">


4.3. registering events with jquery and changing the background color

<! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "http// WWW.W3.ORG/TR/HTML4/LOOSE.DTD ">

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/86/AB/wKiom1fG9sSzg1QDAACXJ2ljeVU039.gif "title=" Change _backgroundcolor2.gif "alt=" wkiom1fg9sszg1qdaacxj2ljevu039.gif "/>



5, which do not need to go to jquery object

Is there a corresponding jquery object for array (array) objects?

The array itself is not a DOM Object. There is no conversion between the jquery Objects.

Using jquery statements you can use arrays directly, like $.each () or $.map ();

parseint () Array These are not required to be converted.

Add

The return value obtained by document.getElementsByTagName () or Document.getelementsbyname () is an array-like value, but not an array, and there is no array-specific method.







jquery Objects and Dom objects

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.