Home > Web Front-end > JS Tutorial > body text

Summary of JQuery basic syntax_jquery

WBOY
Release: 2016-05-16 16:12:23
Original
1044 people have browsed it

1. $(document) converts the document object into jquery

Copy code The code is as follows:

$(document).ready(function(){
alert("hello world");
});

2. Obtain all hyperlink objects and add onclick events; In fact, the underlying jquery object obtains an array of each tag, so we do not need to loop

Copy code The code is as follows:

$(document).ready(function(){
$("a").click(function(){
alert("hello world");
});
});

3. Conversion between jquery objects and dom objects

Copy code The code is as follows:

$(document).ready(function(){
var javascriptElement = document.getElementById("clickme");
//Convert dom object to jquery object
var jqueryElement = $(javascriptElement);
//alert("javascript:" javascriptElement.innerHTML);//innerHTML gets the content of the tag
//alert("jquery:" jqueryElement.html());
//Convert jquery to dom object method 1
var jElement = $("#clickme");
var javascriptEle = jElement[0];
alert("jquery1: " javascriptEle.innerHTML);
//Method 2
var javascriptEle2 = jElement.get(0);
alert("jquery2: " javascriptEle2.innerHTML);
});

4. jquery solves the problem of whether the id value exists

Copy code The code is as follows:

click me

5. It is stipulated in JavaScript that when you want to operate a CSS attribute, you must remove the ‘-’ in the attribute and capitalize the last letter; for example: background-color should be changed to backgroundColor

6. Selectors are also used in jquery to manipulate various elements . It inherits the design concept of CSS, but carries it forward;

7. Several writing forms of jquery

1> Method 1

Copy code The code is as follows:

$("document").ready(function(){
...
});

2> Method 2

Copy code The code is as follows:

$().ready(function(){
...
});

3> Method 3

Copy code The code is as follows:

$(function(){
...
});

The above methods are the same

I hope this article will be helpful to everyone learning jquery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template