【发布时间】:2015-01-06 11:53:33
【问题描述】:
当我单击按钮时,会添加一个类,并且文本从“获取联系”变为“工作”。但是,当我再次单击处于“工作状态”的按钮时,文本不会变回“取得联系”。为什么它不起作用?
小提琴:http://jsfiddle.net/cLgkwjhb/
HTML
<a id="contact-button" href="#">Get in touch</a>
CSS
#contact-button {
background: #000;
background-size: 24px;
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-weight: bold;
padding: 10px 20px;
}
JS
jQuery('#contact-button').click(function( e ){
e.preventDefault();
jQuery(this).addClass('work-button').text('Work');
});
jQuery('#contact-button.work-button').click(function( e ){
e.preventDefault();
jQuery(this).removeClass('work-button').text('Get in touch');
});
【问题讨论】:
标签: javascript jquery css