Home Web Front-end JS Tutorial jquery selector: first-child and :last-child cannot get the solution to the element

jquery selector: first-child and :last-child cannot get the solution to the element

Jun 23, 2017 pm 03:01 PM
jquery last-child Obtain Selector

Let's introduce how to solve this problem through actual code examples. If we have the following HTML code

<a href="#" class="button"><</a>
<a href="#" class="button">></a>
<div id="f">F</div>
<div id="s">S</div>
<div id="t">T</div>
Copy after login

We need to find the last a tag with class button, then according to what we know CSS3pseudo-class, you can easily write the following code

.button:last-child {
    background-color: #ffd700;
}
Copy after login

After running it, I found that the background color of the second a did not change color. After thinking about it, the CSS code must be correct. There must be something wrong with the HTML. After several modifications, I found that the HTML and CSS can be changed to this.

<div>
<a href="#" class="button"><</a>
<a href="#" class="button">></a>
</div>
<div id="f">F</div>
<div id="s">S</div>
<div id="t">T</div>
<style>
div .button:last-child {
    background-color: #ffd700;
}
</style>
Copy after login

At this time, I suddenly realized that first-child and last-child are indeed very arrogant and willful. If the child elements in the father element contain other different tags, they are Very disobedient.

Summary

So what did they listen to and what did they not listen to? After some testing, I came to the conclusion that

When using first, the first child The elements must have the same tag. The middle and last can be different,
last is the opposite, the last element must be the same, the front and middle can be different

The above is the content carefully prepared for you by the editor of Yunqi Community, in Yunqi The community's blogs, Q&A, official accounts, characters, courses and other columns also have relevant content. You are welcome to continue to use the Search button in the upper right corner to search for css. The tag codes are firstchild lastchild and jquery last child. , jquery firstchild, jquery first child, jquery first last, so that you can get more relevant knowledge.

The above is the detailed content of jquery selector: first-child and :last-child cannot get the solution to the element. 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
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 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)

Where to get Google security code Where to get Google security code Mar 30, 2024 am 11:11 AM

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

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 install dual SIM on Realme 12 Pro? How to install dual SIM on Realme 12 Pro? Mar 18, 2024 pm 02:10 PM

Although the general operations of domestic mobile phones are very similar, there are still some differences in some details. For example, different mobile phone models and manufacturers may have different dual-SIM installation methods. Erzhenwo 12Pro, a new mobile phone, also supports dual-SIM dual standby, but how should dual-SIM be installed on this phone? How to install dual SIM on Realme 12Pro? Remember to turn off your phone before installation. Step 1: Find the SIM card tray: Find the SIM card tray of the phone. Usually, in the Realme 12 Pro, the SIM card tray is located on the side or top of the phone. Step 2: Insert the first SIM card. Use a dedicated SIM card pin or a small object to insert it into the slot in the SIM card tray. Then, carefully insert the first SIM card.

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:

How to get free chat times in Taqu How to get free chat times in Taqu How to get free chat times in Taqu How to get free chat times in Taqu Mar 12, 2024 pm 03:58 PM

How to get free chat times in Taqu? Taqu is a very easy-to-use chat and dating software that has helped countless single friends find their ideal partner. In this software, we can easily chat with many netizens and find the one who best fits our soul. However, recently some users found that their free chats had been exhausted when using the software. So, how to solve it? The editor has brought you a way to get free chat times. Friends who are interested should take a look. How to get free chat times with Taqu: First, open Taqu on your phone. Then click on the avatar in the personal homepage. Then click on "Make Friends" below. Finally, we can choose a way to make friends to chat with others. Each of them is

How to get Huang Rong in the mobile game Shooting Condor How to get Huang Rong in the mobile game Shooting Condor Mar 27, 2024 pm 10:36 PM

The Condor Mobile Game is about to be officially launched. Many players want to know how to obtain Huang Rong. Players must first download the [NetEase Master] APP, then join the [Condor Circle] and participate in the Condor Mini Game: SSR Huang Rong will be given for free. How to obtain Huang Rong in the mobile game Condor Shooting 1. First, download the [NetEase Master] APP, and then join the [Condor Shooting Circle]. 2. Go to the Condor Shooting Circle, slide up the page to display the page as shown below, and click [Carving Treasure]. 3. You can also click on the [Play Diaobao Mini Game: SSR Huang Rong for Free] as shown by the arrow in the picture below. 4. Then enter the Diaobao page and click [Yunyou Zhongdu] at the bottom. This is an idle device. Just select the time and direction. 5. Travel around at least six times, choosing a different time and direction each time. 6. Click to claim

How to get fake future crystal coins How to get fake future crystal coins Mar 22, 2024 am 08:00 AM

Many players want to know how to obtain fake future crystal coins. There are actually four different methods, including purchasing gift packages, completing tasks, producing goods, developing land, etc. Players can choose different ways to earn crystal coins according to their needs. The specific content is as follows: Get up and take a look at this guide on how to obtain fake future crystal coins. Fake Future Guide: How to get Fake Future Crystal Coins 1. Purchase the gift package mall to purchase the crystal coin gift package. 2. Obtained by completing tasks and completing main and side tasks. 3. Produce goods. Produce goods in your home to obtain crystal coins. 4. Developing land can also be obtained by developing land, but the reward is one-time.

See all articles