beforeShowDay: This function is called for each day in the datepicker and allows you to specify whether a given day should be selectable.
date.getDay(): This method returns the day of the week as a number, where 0 represents Sunday and 6 represents Saturday.
Condition: The condition day !== 0 && day !== 6 ensures that both weekends (Saturday and Sunday) are disabled.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Datepicker Example</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function() {
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [day !== 0 && day !== 6]; // 0 = Sunday, 6 = Saturday
}
});
});
</script>
</head>
<body>
<input type="text" id="datepicker" placeholder="Select a date">
</body>
</html>