如何使用jQuery对所选行中的标签加粗?

时间:2019-01-16 00:25:59

标签: jquery css

我正在为Bootstrap面板编写代码,我想使所选行的标签变为粗体。这是代码:

HTML:

<div id="costCentersList" class="col-md-6 no-padding-right-left">
<div class="panel panel-default no-MP">
<div class="panel-heading">Cost Centers <span class="floatRight"><a href="#" id="newCostCenter" onClick="newCostCenter();">Create New Cost Center</a></span></div>
<div class="panel-body">
<ul>
<li >
<input type="radio" name="costCenter" value="Marketing" id="btnRadioCC1">
<label >Marketing</label> <span class="floatRight">
<input type="button" value="Assign Employees" class="btn btn-primary btnAssignCC btn-rounded-4">
</span></li>
<li>
<input type="radio" name="costCenter" value="Developer" id="btnRadioCC2">
<label>Developer</label><span class="floatRight">
<input type="button" value="Assign Employees" class="btn btn-primary btnAssignCC btn-rounded-4">
</span></li>
</ul>

jQuery:

$('#costCentersList li').on('click',function(){
$('#costCentersList li').removeClass('highlight-row');
$(this).addClass('highlight-row');
var abc = $(this).find('label');
$('abc').attr('style','font-weight:bold');
})

1 个答案:

答案 0 :(得分:0)

确保类highlight-row具有属性:font-weight:bold

并将函数内容替换为:

$('#costCentersList li label').removeClass('highlight-row');
$(this).find('label').addClass('highlight-row');