<div class="my_class" data-index=0></div>
<div class="my_class" data-index=1></div>
<div class="my_class" data-index=2></div>
<div class="my_class" data-index=3></div>
<div class="my_class" data-index=4></div>
如何使用jquery更改具有类my_class
和data-index=0
的div的css属性。
答案 0 :(得分:3)
查询课程和attribute selector:
$('.my_class[data-index=0]').css('color', 'red');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="my_class" data-index=0>1</div>
<div class="my_class" data-index=1>2</div>
<div class="my_class" data-index=2>3</div>
<div class="my_class" data-index=3>4</div>
<div class="my_class" data-index=4>5</div>
&#13;
答案 1 :(得分:0)
$("[data-index=0]").css('color', 'green');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="my_class" data-index=0>Test</div>
<div class="my_class" data-index=1>Test</div>
<div class="my_class" data-index=2>Test</div>
<div class="my_class" data-index=3>Test</div>
<div class="my_class" data-index=4>Test</div>
&#13;