The jQuery obje...LOGIN

The jQuery object and the dom object call each other's members

Method to obtain the object:

  • ##jquery object: $('li') $('.apple' ) The information returned by the selector is the jquery object

  • dom object: document.getElementById()


##jquery object and dom object call each other’s members

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
        function f1(){
            //$('div').css('background-color','lightgreen');
            //dom对象 调用 jquery对象的成员【失败】
            //document.getElementsByTagName('div')[0].css('background-color','blue');
            //成功
            $(document.getElementsByTagName('div')[0]).css('background-color','blue');
        }
        function f2(){
            //document.getElementsByTagName('div')[0].style.width="400px";
            //jquery对象 调用 dom对象的成员【失败】
            //$('div').style.height = "300px";
            //成功
            $('div')[0].style.height = "300px";
        }
        </script>
        <style type="text/css">
        div {width:300px;height:200px; background-color:pink;}
        </style>
    </head>
    <body>
        <div></div>
        <input type="button" value="触发1" onclick="f1()" />
        <input type="button" value="触发2" onclick="f2()" />
    </body>
</html>

Next Section
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ //$('div').css('background-color','lightgreen'); //dom对象 调用 jquery对象的成员【失败】 //document.getElementsByTagName('div')[0].css('background-color','blue'); //成功 $(document.getElementsByTagName('div')[0]).css('background-color','blue'); } function f2(){ //document.getElementsByTagName('div')[0].style.width="400px"; //jquery对象 调用 dom对象的成员【失败】 //$('div').style.height = "300px"; //成功 $('div')[0].style.height = "300px"; } </script> <style type="text/css"> div {width:300px;height:200px; background-color:pink;} </style> </head> <body> <div></div> <input type="button" value="触发1" onclick="f1()" /> <input type="button" value="触发2" onclick="f2()" /> </body> </html>
submitReset Code
ChapterCourseware