[英]updating class using jquery
In the following html, jquery, bootstrap code, 在下面的html,jquery,bootstrap代码中,
addMenuBar : function addNavigation (component) {
var html = '<ul class="nav nav-pills nav-justified" role="tablist">';
html += '<li id ="scenario" class="disabled"><a href="#">Scenario</a></li>';
html += '<li id ="resolutions" class="disabled"><a href="#">Resolutions</a></li>';
html += '<li id ="triggers" class="disabled"><a href="#">Triggers</a></li>';
html += '</ul>';
component.append(html);
$('ul[id="scenario"] li').addClass("active");
}
where the component is a container div as follows: 组件是一个容器div,如下所示:
this.container = $(document.createElement('div'));
this.container.addClass('patient-hover-inner');
this.container.appendTo(this.form);
I want to change the class for the 'li' item for id = 'scenario' from 'disabled' to 'active'. 我想将id ='scenario'的'li'项的类从'disabled'更改为'active'。 how do i do this? 我该怎么做呢? The above won't work without any errors 以上操作不会没有任何错误
Use switchClass() 使用switchClass()
$('li.disabled').switchClass("disabled", "active");
If you are not using jQuery UI, you can do 如果你不使用jQuery UI,你可以这样做
$('li.disabled').each(function(){
$(this).removeClass('disabled');
$(this).addClass('active');
});
$('ul[id="scenario"] li').addClass("active");
can be 可
$('ul li#scenario').removeClass("disabled").addClass("active");
If a li
has the disabled class it will be removed. 如果li
有禁用的类,它将被删除。 If it doesn't then nothing happens. 如果没有,则没有任何反应。 In either case the 'active' class will be added. 在任何一种情况下,都会添加“有效”类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.