2011-08-23 100 views
0

我需要使用jQuery访问类的帮助,但不知道该如何去做。以下是我的html结构:访问元素的子元素

<div class='a'> 
    <div class='child'> 
    <input type='text'/> 
    </div> 
</div> 
<div class='b'> 
    <div class='child'> 
    <input type='text'/> 
    </div> 
</div> 

现在我需要访问类“a”,而不是“b”的div的'孩子'。在这种情况下,我也可以访问类a的输入吗?

+0

$( 'A:输入')...... http://api.jquery.com/input-selector/ – ppumkin

回答

0

试试这个

var $child = $("div.a .child");//Child of div with class a 

$child.find("input");//This will give you input within div with class child 

//OR you can use this also  

var $input = $("div.a input");//input of div with class a 
0
//the child 
$(".a .child"); 

//the input  
$(".a input"); 
0
// Select all element with class child inside an element with class a 
$('.a .child'); 

// Select all input elements inside all elements with class a 
$('.a input');