Jquery sample code that determines whether children of an element exist

  • 2020-03-30 01:35:36
  • OfStack

Jquery determines the existence of child elements    

1. Determine whether a child element exists    
// first level child element if($("#specialId> Img "). The length = = 0)        
If ($(" # specialId: from the (img) "). The length = = 0)                  
{     
  //-- no img submark --       
}      
Else       
{     
  //-- with img submark --       
}      

Select a child element of a specific id under a specific id element      
$("#form"). Children ("# t") so      

Select the child element   under a specific id element;    
$(" ul# u> Li :nth-child(2)") so      

Determine whether an element exists      
If ($(" # myId "). Length> 0)      
{     
    / / there        
}  


Related articles: