Home Web Front-end JS Tutorial Use jQuery to manage selection results_jquery

Use jQuery to manage selection results_jquery

May 16, 2016 pm 04:19 PM
jquery manage

The elements selected using jQuery are very similar to arrays. They can be processed through a series of methods provided by jQuery, including length, finding an element, intercepting a paragraph, etc.

1. Get the number of elements.

In jQuery, you can get the number of elements in the selector through the size() method, which is similar to the length attribute in an array and returns an integer value, for example:

$("img").size()
Get the number of all images on the page

The following is an example of adding div blocks by continuously clicking and calculating the

blocks in the page.

Copy code The code is as follows:


       
       
1

       
2

       
3

       
4

       
5

       
6

上面代码将页面本身的6个

块用get()方法转化为数组,然后用数组反序reverse(),并传给displayleb()函数,再将其一个个现在页面中。

get(index)方法可以获取指定位置的元素,反过来,index(element)方法可以查找元素的element所处的位置。例如

var iNum=$("li").index($(li[title=isaac]")[0])
以上取

  • 标记在整个
  • 标记列表所处的位置,并将该位置返回给整数iNum.如下举例index(element)方法的典型运用。

    例:用index()方法获取元素的序号

    复制代码 代码如下:


           
           

           

           

           

           

           

           

    以上的Jquery通过not()的方法去掉风格为"green"和"blueone"的

    块,给剩下的div块加altcss样式。

    not()方法所接收的参数都不能包含特定的元素,只能是通过通用的表达式例如下面的代码是错误的

    $("li[title]").not("img[title*=isaac]")
    正确的写法是:

    $("li[tile]").not("[title*=isaac]")
    除了add()和not()外,jQuery还提供了更强大的filter()方法来筛选元素。filter()可以接受两种类型的参数,一种与not()方法一样,接受通用的表达式。代码如下:

    $("li").filter("[title*=isaac]")
    以上的代码表示:筛选出title值包含isaac字符串的li元素组合。

    $("li[title*=isaac]")
    所筛选的组合相同。

    复制代码 代码如下:

           


           

           

           

           

           

    In the above code, four of the class attributes are middle. Jq first adds css1 styles to all div blocks, and then uses the filter() method to add css2 styles to the divs containing middle in the class.

    In the parameters of filter(), you cannot directly equal to match (=), you can only use pre-match (^=), post-match (&=), or any match (*=).

    The other type of parameter of filter() is a function, which matches and retains the returned true element, otherwise the collection is excluded. Function parameters are very powerful and allow users to customize filtering functions.

    For example:

    Copy code The code is as follows:

    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
    4 weeks 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

    How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

    How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

    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:

    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

    Research on the role and management methods of home directory in Oracle database Research on the role and management methods of home directory in Oracle database Mar 07, 2024 pm 02:27 PM

    Exploring the role and management methods of the master directory in the Oracle database. In the Oracle database, the master directory (MasterDirectory) is an important object. Its main function is to specify the default storage location of all data files and control files in the Oracle database. By setting the home directory, you can easily manage the storage and access of database files and improve the performance and security of the database. The home directory can be managed in the following ways: 1. Create a home directory To create a home directory, you can

    Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

    目录1:basename()2:copy()3:dirname()4:disk_free_space()5:disk_total_space()6:file_exists()7:file_get_contents()8:file_put_contents()9:filesize()10:filetype()11:glob()12:is_dir()13:is_writable()14:mkdir()15:move_uploaded_file()16:parse_ini_file()17:

    See all articles