JQuery JavaScript test
Testing JavaScript framework library - jQuery
Reference jQuery
To test JavaScript library, you need to reference it in a Web page.
To refer to a library, use the <script> tag, whose src attribute set to the URL library:
Reference jQuery
<html>
<head>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</script>
</head>
<body>
</body>
</html>
jQuery Description
The main function is a jQuery $ () function (jQuery function). If you pass DOM object to a function that returns the jQuery object with jQuery to add the functionality.
jQuery CSS selector allows you to select elements.
In JavaScript, you can assign a function to handle window load event:
JavaScript method:
{
var obj = document.getElementById ( "h01");
obj.innerHTML = "Hello jQuery";
}
onload = myFunction;
Equivalent jQuery is different:
jQuery way:
{
$("#h01").html("Hello jQuery");
}
$(document).ready(myFunction);
The last line of the code above, HTML DOM document object is passed to jQuery: $ (document).
When you pass DOM object to jQuery, jQuery will return to the HTML DOM objects wrapped jQuery object.
jQuery function returns a new jQuery object, wherein the ready () is a method.
Since the function is variable in JavaScript, so you can put myFunction passed as an argument to the jQuery ready methods.
jQuery return the jQuery object, the DOM object has passed different. JQuery object properties and methods have, with different DOM object. You can not use HTML DOM properties and methods on the jQuery object. |
Testing jQuery
Please try the following example:
Examples
<html>
<head>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</script>
<script>
function myFunction()
{
$("#h01").html("Hello jQuery")
}
$(document).ready(myFunction);
</script>
</head>
<body>
<h1 id="h01"></h1>
</body>
</html>
try it"
Please try again at this example:
Examples
<html>
<head>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js">
</script>
<script>
function myFunction()
{
$("#h01").attr("style","color:red").html("Hello jQuery")
}
$(document).ready(myFunction);
</script>
</head>
<body>
<h1 id="h01"></h1>
</body>
</html>
try it"
As you can see in the example above, jQuery allows links (chain syntax).
Link (Chaining) is a method of performing multiple tasks on the same subject convenient method.
You need to learn more? This tutorial gives you a great jQuery tutorial .