Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does datepicker highlight not work when I use "=="?

   .Highlighted a{
   background-color : Green !important;
   background-image :none !important;
   color: White !important;
   font-weight:bold !important;
   font-size: 9pt;

}


  $(document).ready(function () {

                var date1 = new Date(2014, 5, 6);
                var date2 = new Date(2014, 5, 17);

                $('#datepicker').datepicker({

                   dateFormat: "mm/dd/yy",

                   beforeShowDay: function (date) {


                       if (date == date1 ) {

                            return [true, 'Highlighted', 'Available Date'];
                        }
                        return [false, '', ''];
                    }
                });
        });

This one doesn't work, because of date==date1. If I change it to date<=date1, it works fine. I thought javascript is a weakly typed language and it compares the content, rather than reference. I don't wanna do something like (date.getDay==date1.getDay &&....). Is there an easier way to compare the values?

like image 483
An Overflowed Stack Avatar asked Jun 20 '14 16:06

An Overflowed Stack


People also ask

How do I highlight a specific date in datepicker?

datepicker({ beforeShowDay: function( date ) { var highlight = eventDates[date]; if( highlight ) { return [true, "event", 'Tooltip text']; } else { return [true, '', '']; } } }); The complete JavaScript code to highlight specific dates.

How do you change the color of the datepicker?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Kindly fine the highlighted code, this is the simplest way to change the colour of your datePicker.

How do I fix my datepicker position?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.

Why datepicker is not working in HTML?

Try using a more recent version of jQuery UI that is compatible with jQuery 1.9+. See Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools. Consider using jQuery 1.9. 1, but it appears to work fine with 1.9.


1 Answers

Demo Fiddle

Use the + unary operator (reference) to convert the values to numerics for comparison.

The unary + operator converts its operand to Number type.


if (+date === +date1 ) {

      return [true, 'Highlighted', 'Available Date'];
}

OR

if (!(date - date1)) {

      return [true, 'Highlighted', 'Available Date'];
}
like image 122
Shaunak D Avatar answered Sep 28 '22 14:09

Shaunak D