Home  >  Article  >  Web Front-end  >  jquery sample code to determine whether the child elements of an element exist_jquery

jquery sample code to determine whether the child elements of an element exist_jquery

WBOY
WBOYOriginal
2016-05-16 17:01:26870browse

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 }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn