jquery gets sibling elements

Source: Internet
Author: User

According to the school guidelines, jquery, in order to get an element of the brother, you can use Prev (), Next () two methods. As the name implies, Prev () Gets the previous one, next () gets the back one.

The problem is that if there are brothers before and after, the two methods may return real deal objects; return what? Is it null?

The answer is no. If you want to use if ($ ("#div1"). Prev () = = null) {alert ("No");}, destined to hit the board. Because it will never be null.

I tried it and tried it, and I ended up doing it this way:

            if (typeof $("#div1""undefined") {                alert("没啦");            }

Most hate online those articles, a big copy, a piece of oath, but only to say something known, not practical, the key moment unreliable.

Get a sibling's usage scenario, such as a page sign. Click on a tab, will this be the first one or the last one?

Copyright NOTICE: This article for Bo Main original 屙 article, like you take away.

jquery gets sibling elements

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.