fix this uncaught error: syntax error, unrecognized expression: .timeslot-time[data-start=17:00] in javascript

This error usually occurs when there's an invalid selector passed in the jQuery function. The issue is that the selector is not properly formatted as a CSS selector.

The problem here is that 17:00 is not a valid value to be used directly in a selector, as : is a reserved character in CSS selectors.

A solution to fix this issue is to escape the : character using two backslashes \\: in the selector string like this:

var timeSlot = $('.timeslot-time[data-start=17\\:00]');
56 chars
2 lines

Alternatively, you can also use the attribute selector without quotes, like this:

var timeSlot = $('.timeslot-time[data-start=17:00]');
54 chars
2 lines

Then you can add an error handling when parsing the selector:

try{
   var timeSlot = $('.timeslot-time[data-start=17:00]');
} catch(error) {
   console.log("Error occurred while parsing selector: ", error.message);
}
155 chars
6 lines

This way, you can handle errors that may occur during the jQuery selector parsing.

gistlibby LogSnag