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
Use the textContent property to get the text of a span element, e.g. const text = span. textContent . The textContent property will return the text content of the span and its descendants.
Default value of HTML span attribute is 1.
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.
I think you want .text():
var monthname = $(this).text();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With