0

I am trying to access the left .hourselect in the daterangepicker. But I cant get it working for some strange reason. Here is what the html looks like:

html

I am trying to access the .hourselect class from the .calendar.left div.

There is a calendar right which has the same elements inside of it and that is why I need to use the .calendar.left to get the .hourselect element I want.

Here is the code I have tried which doesnt work:

$(document).on('change', 'div.calendar.left > div.daterangepicker_input > div.calendar-time > div > select.hourselect', function() {
    alert(this.value);
    console.log(this);
});

Has anyone came across this issue or know a way to get around this issue? I don't want to edit the actual library so I was trying to catch the value so I can use javascript to do what I want.

Thanks for any help in advance :)

Luke Rayner
  • 391
  • 6
  • 20
  • 1
    Why do you need to do this? It would make more sense to use the events that the datepicker control exposes to change content after a value is selected – Rory McCrossan Jan 29 '18 at 10:24
  • @RoryMcCrossan what events do they have? I am trying to make it so cant make the end hour less then the start hour. Which means people cant select times ranges which go over midnight – Luke Rayner Jan 29 '18 at 10:33
  • It changes depending on which control you're using. – Rory McCrossan Jan 29 '18 at 10:41
  • Duplicate or almost of https://stackoverflow.com/questions/30456270/bootstrap-datepicker-change-mindate-startdate-from-another-datepicker – mplungjan Jan 29 '18 at 10:41
  • I need to access the value before I press submit. So I need to use onchange function to grab the value when the left hour is selected. Do you know how to grab that value from the HTML I display in my question? Thats all I want to know please – Luke Rayner Jan 29 '18 at 10:46
  • I have now removed everything to do with the datetimepicker – Luke Rayner Jan 29 '18 at 10:48
  • What does the `console.log` return ? – Anatol Bivol Jan 29 '18 at 10:56
  • @AnatoliiBivol it isn't returning anything, so it seems like it isn't looking at the correct page element. But in my opinion the code I wrote looks correct – Luke Rayner Jan 29 '18 at 11:02
  • @LukeRayner Can't really help you without a view of the actual page and debug that. I would go on and try to select the element first at creation and then bind to the change event. If you have an online demo of the current code or a jsfiddle we could help – Anatol Bivol Jan 29 '18 at 11:20

0 Answers0