我想要附加课程' activeTab'准备好文件上的标签。我需要通过它的数据-html选择标签,但我不知道如何做到这一点。
这就是html当前加载的方式:
<ul class="tabbedGroupings_tabs">
<li class="tg_tab" data-html="academicprofessionalanddevelopment">Academic, Professional and Development</li>
<li class="tg_tab" data-html="cultural">Cultural</li>
<li class="tg_tab" data-html="physicalactivityandperformance">Physical Activity and Performance</li>
<li class="tg_tab" data-html="politicsreligionandcampaigning">Politics, Religion and Campaigning</li>
<li class="tg_tab" data-html="society">Society</li>
<li class="tg_tab" data-html="specialinterest">Special Interest</li>
<li class="tg_tab" data-html="all">All</li>
</ul>
我想添加&#39; activeTab&#39; class data-html="all"
元素。
答案 0 :(得分:1)
您可以使用jQuery属性选择器。 $("[attribute]")
,它将选择具有指定属性的元素,其值恰好等于某个值。attribute-equals-selector
$(document).ready(function() {
$(".tabbedGroupings_tabs > [data-html='all']").addClass('activeTab');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="tabbedGroupings_tabs">
<li class="tg_tab" data-html="academicprofessionalanddevelopment">Academic, Professional and Development</li>
<li class="tg_tab" data-html="cultural">Cultural</li>
<li class="tg_tab" data-html="physicalactivityandperformance">Physical Activity and Performance</li>
<li class="tg_tab" data-html="politicsreligionandcampaigning">Politics, Religion and Campaigning</li>
<li class="tg_tab" data-html="society">Society</li>
<li class="tg_tab" data-html="specialinterest">Special Interest</li>
<li class="tg_tab" data-html="all">All</li>
</ul>