tags:

views:

34

answers:

3

Giving this html, i want to grab "August" from it when i click on it:

<span class="ui-datepicker-month">August</span>

i tried

$(".ui-datepicker-month").live("click", function () {
    var monthname =  $(this).val();
    alert(monthname);
});

but doesn't seem to be working

+6  A: 

Instead of .val() use .text(), like this:

$(".ui-datepicker-month").live("click", function () {
    var monthname =  $(this).text();
    alert(monthname);
});

.val() is for input type elements (including textareas and dropdowns), since you're dealing with an element with text content, use .text() here.

Nick Craver
+1... 4 seconds...
GenericTypeTea
+2  A: 

I think you want .text():

var monthname = $(this).text();
Matthew Jones
A: 

val() is for input elements, use html() instead

graycrow