JQuery Method for operating the nth element of the same group element

Source: Internet
Author: User
Tags mysql index

JQuery Method for operating the nth element of the same group element

Jquery operates on the nth element of the same group element. Example:

There are 3 ul under class = "phpernote", and now you want to add class = "com" to the 5th li elements under each ul"

Specific jQuery code:

$ (". Phpernote ul li: nth-child (5)"). addClass ("com ");

You have successfully added the class com to the 5th li in each ul.

Of course, you can also directly add the CSS code:

$ (". Phpernote ul li: nth-child (5)" ).css ({"padding-right": "5px "});

Nth-child: the abbreviation in English, n-th, which indicates the nth number, 1, 2, and 3 respectively. They use the first, second, and third words respectively, and start from 4 as the number word + th, such as 4th, 5th, and 6th

Obtain the first li in ul.

$ ("Ul li: first-child ")

Obtain the last li in ul.

$ ("Ul li: last-child ")
Articles you may be interested in
  • How does php Delete the first and last elements of an array?
  • How does jquery operate on iframe parent page elements?
  • Js gets the last element of the array
  • MySQL index Operation Command (create index, re-index, query index, delete index) Summary
  • Eight typical Linux operating system applications
  • How to insert an element to the front of the body element in js
  • Jquery obtains the index number of the current element in the Peer element.
  • Php retrieves the last element of the array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.