Home > Article > Web Front-end > jquery sample code to determine whether the child elements of an element exist_jquery
jquery determines whether a child element exists
1. Determine whether the sub-element exists
//First-level sub-element if($("#specialId>img").length==0)
if ($( " #specialId:has(img)" ).length==0)
//-------There is an img sub-tag------
}
2. Select the specific id sub-element under the specific id element
$("#form" ).children( "#t" ) like this
3. Select the child element under a specific id element
$("ul#u> ;li:nth-child(2)" ) So
4. Determine whether an element exists
if ($( "#myId" ).length>0)
{
//Existence }