JQuery dump release date

I am using jQuery datepicker and I want to display the date when the user is currently hovered over. I have below code (you can also try the code from JSFiddle, http://jsfiddle.net/JGM85/ ):

$(function() {
    $("#datepicker").datepicker();
    $(".ui-state-default").live("mouseenter", function() {
        $("h1").text($(this).text());
    });
});

      

Currently, when hovering over a date, the label number (i.e. 23) is outputted in h1 tags. I want to change this so that it outputs the entire date and stores it in a variable.

Any help with this would be greatly appreciated.

+3


source to share


1 answer


This is not the best way, I did it because I couldn't find anything in the jQuery UI Datepicker documentation for getting the actual date, but here you go:

$(function() {
    $("#datepicker").datepicker();
    $(".ui-state-default").on("mouseenter", function() {
        $("h1").text($(this).text()+"."+$(".ui-datepicker-month",$(this).parents()).text()+"."+$(".ui-datepicker-year",$(this).parents()).text());
    });
});

      

http://jsfiddle.net/JGM85/1/

Second version keeping actual date + warnings after it:



$(function() {
    $("#datepicker").datepicker();
    $(".ui-state-default").on("mouseenter", function() {
        $("h1").text($(this).text()+"."+$(".ui-datepicker-month",$(this).parents()).text()+"."+$(".ui-datepicker-year",$(this).parents()).text());
    var actualDate=$('h1').text();
        alert(actualDate);
    });
});

      

http://jsfiddle.net/JGM85/2/

UPDATE: I used to have .live as an event handler, but .live is not deprecated and the .on () method is a method.

+7


source







All Articles