您好,我想将类添加到父 div 之后的 div 的范围中。
HTML
<div class="stepwizard">
<ul class="stepwizard-row">
<li class="stepwizard-step">
<span class="step-border"><a href="#step1" class="data-toggle="tab">1</a></span>
//If user click here <span class="step1"> should be change
</li>
<li class="stepwizard-step">
<span class=""><a href="#step2" data-toggle="tab" >2</a></span>
//If user click here <span class="step2"> should be change
</li>
<li class="stepwizard-step">
<span class=""><a href="#step3" class="p-n-t step-tab" aria-controls="documents" role="tab" data-toggle="tab">3</a></span>
//If user click here <span class="step3"> should be change
</li>
</ul>
</div>
<div class="m-t-sm step-title">
<span class="step1">BASIC INFO</span> //here i want to add class
<span class="step2">REGISTERED NUMBERS</span>
<span class="step3">CLIENT SERVICES</span>
</div>
此处当用户单击<a>
时我想将类添加到 <span>
标签在 <div class="m-t-sm step-title">
之后.
如何使用 jquery 做到这一点?
最佳答案
请尝试一下
$(document).ready(function(){
$("a").click(function(){
var position = $(this).attr('href').split("#")[1];
$('.'+position ).addClass('your_class')
});
});
关于jquery - 更改父div之后的div的css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34873861/