2013-05-02 28 views
0

我有一個由CRM生成的表單。Jquery .children() - 父級擁有獨特的類,子級具有非唯一類,選擇子級

<fieldset><legend>Publish Name in Newspaper 
    </legend> 
<div class="crm-section custom_67-section"><div class="label"><label> Check here if we may release your name and contribution levels 
<span class="crm-marker" title="This field is required.">*</span> 
</label></div> 
<div class="content"> 
<input value="1" type="radio" id="CIVICRM_QFID_1_20" name="custom_67" class="form-radio" /> 
<label for="CIVICRM_QFID_1_20">Yes</label>&nbsp; 
<input value="0" type="radio" id="CIVICRM_QFID_0_22" name="custom_67" class="form-radio" /> 
<label for="CIVICRM_QFID_0_22">No</label></div> 
<div class="clear"></div></div></fieldset> 

由於類「標籤」使用的形式反覆其他地方,我只是需要選擇div class="crm-section custom_67-section"div class='label'

這是我

jQuery(document).ready(function(){ 
    jQuery(.'crm-section custom_67-section').children(.'label').attr("style","width:500px;"); 
}); 
+3

'.'進入字符串中。 ''.crm-section.custom_67-section''.label'' – Musa 2013-05-02 21:37:59

+1

'jQuery('.crm-section custom_67-section')' – 2013-05-02 21:38:32

回答

0

的多個相同的元素類選擇使用多個點。

jQuery('.crm-section.custom_67-section') 

.'也是無效的語法..應該是'.代替。

最後,您應該使用.css來設置樣式,而不是更新樣式屬性。

+0

Thanks!這是漫長的一天,有時是最簡單的解決方案。 – user2344862 2013-05-02 21:57:37

0

這應該工作:

jQuery(document).ready(function(){jQuery('.crm-section custom_67-section .label').attr("style","width:500px;");}); 
0

首先,點雲內「...」:$('.yourClass')

其次,當一個元素有2類,你需要點爲每個類和無空間:.crm-section.custom_67-section

第三,點是在html節點上選擇類的方法。例如:

<div class='hello'> --> $('.hello') 

標籤的arent類,所以讓他們你需要寫children('label')

最後,而不是attr('style', 'width : 400px'),寫`CSS( '寬', '400像素')

決賽代碼:

jQuery(document).ready(function(){ 
    jQuery('.crm-section.custom_67-section').children('label').css('width',"500px;"); 
}); 
相關問題