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