Jquery .children() - 父类具有唯一类,子类具有非唯一类,选择子类

时间:2013-05-02 21:35:30

标签: jquery css jquery-selectors parent

我有一个由CRM生成的表单。

  <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='label'内的div class="crm-section custom_67-section"

这就是我所拥有的

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

3 个答案:

答案 0 :(得分:0)

同一元素的多个类选择器使用多个点。

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

.'也是无效的语法..应该是'.

最后,您应该使用.css来设置样式,而不是更新样式属性。

答案 1 :(得分:0)

这应该有效:

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

答案 2 :(得分:0)

首先,点进入'...':$('.yourClass')

其次,当一个元素有2个类时,每个类都需要一个点而没有空格:.crm-section.custom_67-section

第三,点是在html节点上选择类的方法。例如:

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

标签不是类,因此您需要编写children('label')

最后,代替attr('style', 'width : 400px'),写出`css('width','400px')

最终代码:

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