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
Instead of .val()
use .text()
, like this:
$(".ui-datepicker-month").live("click", function () {
var monthname = $(this).text();
alert(monthname);
});
Or in jQuery 1.7+ use on()
as live
is deprecated:
$(document).on('click', '.ui-datepicker-month', 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.