I created a simple calendar with html and now want the current date to highlight automatically with javascript. I know of a few ways to do this but I am looking for the most simple.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It really depends on how your calendar works. You can get the client’s current date with the following JavaScript:
Once you have that, you’ll have to use the built in date functions to get the current date element and probably add a class to it that will style it as highlighted.
UPDATE
Assuming you have your
lielements withid="dayElement_x"wherexis the day number, and your class for highlighting your day iscurrentDay, an example JavaScript call would be:UPDATE 2
I just thought of a solution where you can do this without having a bunch of ids. Here is the JavaScript: