2011-08-23 102 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');