jquery object into a target dom

 JQuery library on the nature or JavaScript code, it's just JavaScript language packaging process, in order to provide better and more convenient and efficient DOM processing and development of frequently used functions. We can also use the jQuery JavaScript hybrid native code used together. In many scenarios, we need to be able to DOM jQuery mutual conversion, DOM elements which are operable, jQuery array is a class object, and DOM object is a single DOM element.

 

How the jQuery object into a DOM object
JQuery manner to read the target objects in the DOM by using the array
1, we would have some project id, after obtaining the required by jquery dom converted into objects

 

 2, to find all the div element (3) with jQuery, since the structure is an array jQuery object, a div element can be found first by indexing the array subscript

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="http://code.jquery.com/jquery-1.11.3.js"></script>
</head>
<body>
    <div>元素一</div>
    <div>元素二</div>
    <div > element three </ div > 
    
    < Script type = "text / JavaScript" > 
        var $ div = $ ( ' div ' ); // the jQuery objects 
        var div = $ div [ 0 ] ; // converted to dom objects 
        div. style.color =  ' Red ' ; // operational attribute object dom 
    </ Script > 
</ body > 
</ HTML >

 

JQuery comes through get () method
<!DOCTYPE html>
<html>


<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="http://code.jquery.com/jquery-1.11.3.js"></script>
</head>


<body>
    <div>元素一</div>
    <div>元素二</div>
    <div > element three </ div > 
    
    < Script type = "text / JavaScript" > 
        var $ div = $ ( ' div ' ); // the jQuery objects 
        var div = $ div.get ( 0 ) ; // converted to objects dom 
        div.style.color =  ' Red ' ; // operational attribute object dom 
    </ Script > 
    
</ body > 


</ HTML >

 

 

Guess you like

Origin www.cnblogs.com/wzndkj/p/11725760.html