Hai ,
I am creating a DatetimePicker User control. I just want to know how to get the selected date of the calendar (asp.net control) control using jQuery. I used this code, but it's wrong.
$(document).ready(function() {
$(".UserCalender").click(function () {
var a = $('.CalenderDiv:selected').text();
alert(a);
});
});
What's wrong with this?
You won't be able to do like this. There is no :selected selector for an anchor tag. It works only for <option>
elements. What you can do is to attach an event hanlder to each anchor ag and use the text() method. Something like
$("#Calendar1 a").click(function(){
alert ( $(this).text() );
return false;
});
But why do you want to do this. By doing like this you will get only the text inside the anchor tag and not the whole date. To get the whole date you will have to perform additional work.
If you want to manipulate the selected text then you can use any datepicker plugin from jQuery.
See jQuery UI Datepicker
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