Sample Code for jquery to determine whether the child element of an element exists _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces the sample code for jquery to determine whether the child element of an element exists. If you need it, you can refer to it and hope to help jquery determine whether the child element exists.

1. Determine whether a child element exists
// If ($ ("# specialId> img"). length = 0)
If ($ ("# specialId: has (img)"). length = 0)
{
// ----- No img sub-mark -----
}
Else
{
// ------- There is an img submark ------
}

2. Select a specific id sub-element under a specific id Element
$ ("# Form"). children ("# t") so

3. Select child elements under a specific id Element
$ ("Ul # u> li: nth-child (2)") so

4. determine whether an element exists
If ($ ("# myId"). length> 0)
{
// Exists
}

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.