Javascript或Jquery:更改所选id的属性的CSS

时间:2016-08-30 09:00:29

标签: javascript jquery css

我有这段代码:

<span id="sn1">
<a href="javascript:removeEtape(2);" class="glyphicon glyphicon-remove"></a>
<a id="aUn1" href="javascript:upEtape(1,0);" class="glyphicon glyphicon-chevron-up" aria-hidden="true"></a>
<a id="aDn1" href="javascript:downEtape(1,2);" class="glyphicon glyphicon-chevron-down" aria-hidden="true"></a>
my text here<br></span>

选择id“aUn1”后,我需要更改“glyphicon glyphicon-chevron-up”的颜色。

我试试这个但是,它不起作用:

$('#aUn1').attr('[class$="glyphicon-chevron-up"]').css('color', 'grey');

你能帮我吗?

2 个答案:

答案 0 :(得分:2)

只需将class添加到selector

$('#aUn1.glyphicon-chevron-up').css('color', 'grey');

答案 1 :(得分:-1)

像这样更新您的代码

$(".glyphicon-chevron-up").css('color', 'grey');