Home Web Front-end JS Tutorial Summary of usage examples of DOM elements and attributes in jquery

Summary of usage examples of DOM elements and attributes in jquery

Jun 19, 2017 am 10:52 AM
jquery Example Attributes usage

DOM element methods

1. .get()

1

2

3

4

5

6

$(selector).get(index)//可选。规定获取哪个匹配元素(通过 index 编号)。

//get() 方法获得由选择器指定的 DOM 元素

$("button").click(function(){

  x=$("p").get(0);

  $("div").text(x.nodeName + ": " + x.innerHTML);

});//获得第一个 p 元素的名称和值

Copy after login

2. .index()

1

2

3

4

5

$(selector).index()//获得第一个匹配元素相对于其同胞元素的 index 位置,如果未找到元素,index() 将返回 -1。

$(selector).index(element)//获得元素相对于选择器的 index 位置

$("li").click(function(){

  alert($(this).index());

});//获得第一个 p 元素的名称和值

Copy after login

3. .size()

1

$(selector).size()//返回被 jQuery 选择器匹配的元素的数量

Copy after login

4. .toArray()

1

2

3

4

5

6

7

8

$(selector).toArray()//以数组的形式返回 jQuery 选择器匹配的元素

$("button").click(function(){

  x=$("li").toArray()

  for (i=0;i<x.length;i++)

    {

    alert(x[i].innerHTML);

    }

});//将 li 元素转换为数组,然后输出该数组元素的 innerHTML

Copy after login

Attributes

1. jquery

The string returned by the jquery attributecontains the version number of jquery

1

2

3

4

5

$().jquery

$("button").on("click",function(){

  var version = $().jquery;

  alert("You are running jQuery version: " + version);

});

Copy after login

2. jQuery.fx.interval

jQuery.fx.interval = milliseconds;

jQuery.fx.interval property is used to change the animation running rate in milliseconds. This property can be manipulated to adjust the number of frames per second at which the animation runs.

Specifies the animation running rate in milliseconds. The default is 13 milliseconds

1

2

3

4

5

6

$("#toggle").on("click",function(){

  $("div").toggle(5000);

});

$("#interval").on("click",function(){

  jQuery.fx.interval = 500;

});//以较少的帧数来运行 <div> 元素的动画

Copy after login

3. jQuery.fx.off

jQuery.fx.off property is used to globally disable or enable all animations

jQuery.fx. off = true|false;

The default value is false, which allows the animation to run normally. When set to true, all animation methods will be disabled, which will set the element to its final state instead of displaying the effect

1

2

3

4

5

6

7

8

9

$("#true").click(function(){

  jQuery.fx.off = true;

});

$("#false").click(function(){

  jQuery.fx.off = false;

});

$("#toggle").click(function(){

  $("div").toggle("slow");

});

Copy after login

4. jQuery.support

jQuery.support.propvalue

The jQuery.support property contains a set of properties that represent different browser features or vulnerabilities.

This property is mainly used internally by jQuery

1

2

3

$(document).ready(function(){

  $("p").html("This browser can create XMLHttpRequest object: " + jQuery.support.ajax);

});测试浏览器是否能创建 XMLHttpRequest 对象

Copy after login

5. length

The length property contains the number of elements in the jQuery object

1

2

3

4

$(selector).length

$("button").click(function(){

  alert($("li").length);

});//输出 <li> 元素的数目

Copy after login

The above is the detailed content of Summary of usage examples of DOM elements and attributes in jquery. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Detailed explanation and usage introduction of MySQL ISNULL function Detailed explanation and usage introduction of MySQL ISNULL function Mar 01, 2024 pm 05:24 PM

The ISNULL() function in MySQL is a function used to determine whether a specified expression or column is NULL. It returns a Boolean value, 1 if the expression is NULL, 0 otherwise. The ISNULL() function can be used in the SELECT statement or for conditional judgment in the WHERE clause. 1. The basic syntax of the ISNULL() function: ISNULL(expression) where expression is the expression to determine whether it is NULL or

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

The relationship between the number of Oracle instances and database performance The relationship between the number of Oracle instances and database performance Mar 08, 2024 am 09:27 AM

The relationship between the number of Oracle instances and database performance Oracle database is one of the well-known relational database management systems in the industry and is widely used in enterprise-level data storage and management. In Oracle database, instance is a very important concept. Instance refers to the running environment of Oracle database in memory. Each instance has an independent memory structure and background process, which is used to process user requests and manage database operations. The number of instances has an important impact on the performance and stability of Oracle database.

Introduction to the attributes of Hearthstone's Despair Thread Introduction to the attributes of Hearthstone's Despair Thread Mar 20, 2024 pm 10:36 PM

Thread of Despair is a rare card in Blizzard Entertainment's masterpiece &quot;Hearthstone&quot; and has a chance to be obtained in the &quot;Wizbane's Workshop&quot; card pack. Can consume 100/400 arcane dust points to synthesize the normal/gold version. Introduction to the attributes of Hearthstone's Thread of Despair: It can be obtained in Wizbane's workshop card pack with a chance, or it can also be synthesized through arcane dust. Rarity: Rare Type: Spell Class: Death Knight Mana: 1 Effect: Gives all minions a Deathrattle: Deals 1 damage to all minions

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

See all articles