jQuery Datepicker onSelect addClass
Is there a way to add a class with jQuery's addClass to an anchor element for a date in datepicker?
For example, each time a date is clicked on an inline datepicker instance, I want the border to be red (this instance of datepicker is not assigned to an input element). If clicked again afterward, the color can return to transparent (or whatever the original color was.) I tried using onSelect, but there was no way to get the specific anchor for the date; so I tried
$('td a.ui-state-default').live( 'click', function () {})
when I used hasClass, addClass, and removeClass to achieve the effect I want, the element app开发者_如何转开发arently had the class--but would be either reverting/overwritten or simply not link the proper style rules. Any suggestions on how to get this effect working?
You can do this with straight CSS.
table.ui-datepicker-calendar a.ui-state-default.ui-state-active {
border: 2px solid red;
}
Demo: http://jsfiddle.net/mattball/N7wpE/
JS
$('.ui-state-default').click(function(){
if($(this).hasClass('red')){
$(this).removeClass('red');
}else{
$(this).addClass('red');
}
});
CSS
.red { border: 1px solid #f00; }
精彩评论