Web front end - jQuery

1. Any method of the DOM object cannot be used in the jQuery object. Likewise, DOM objects cannot use methods in jQuery.

2. Interconversion between jQuery objects and DOM objects.

1) What is a jQuery object?  

  • A jQuery object is an object generated by wrapping a DOM object with jQuery. That is, the jQuery object is an array -like object.
  • The jQuery objects that are usually used are created by the $() function, and the $() function is a jQuery object manufacturing factory.

2) Before discussing the mutual conversion between jQuery objects and DOM objects, first agree on the style of defining variables.

  1. Get the jQuery object: var $variable = jQuery object;
  2. Get DOM object: var variable = DOM object;

3) There are two conversion methods for jQuery objects to convert DOM objects.

  1. The [index] method treats the jQuery object as an array

var  $cr  =  $("#cr");

var cr = $ cr [0];

  1. get(index)

var $cr  =  $("#cr");

var cr    =  $cr.get(0);

4) Convert DOM object to jQuery object For a DOM object, you only need to wrap the DOM object with $() to get a jQuery object. The method is $(DOM) object.

var  cr  =  document.getElementById("cr");

var $ cr = $ (cr);

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324533594&siteId=291194637