Using jQuery, is there a quick way of knowing if an element is its parent”s last child?

Example:

$(“#b”).isLastChild(); //should return FALSE$(“#c”).isLastChild(); //should return TRUE

*

Trending sort Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

Đang xem: Check if element is last child jquery code example

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)

*

You can use .is() with :last-child like this:

$(“#b”).is(“:last-child”); //false$(“#c”).is(“:last-child”); //trueYou can test it here. Another alternative is to check .next().length, if it”s 0 it”s the last element.

Xem thêm: Test Cung Hoàng Đạo ? Bạn Nên Hẹn Hò Với Cung Hoàng Đạo Nào

*

*

*

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

Xem thêm: Những Thông Tin Cần Biết Về Ung Thư Quai Hàm Ác Tính, Ung Thư Xương Hàm Là Gì

To learn more, see our tips on writing great answers.

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged jquery or ask your own question.

Selecting and manipulating CSS pseudo-elements such as ::before and ::after using javascript (or jQuery)
Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev2022.8.26.42925

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *