I think this will do what you want:
$(window).on('load', function(){
let hr = new Date().getHours(),
cls = 'opened';
// I want execute this at 20:00 till 04:00
$('#tahajud').toggleClass(
cls,
(hr >= 20) || (hr < 5)
);
// I want execute this at 04:00 till 06:00
$('#fajr').toggleClass(
cls,
(hr >= 4) && (hr < 6)
);
// I want execute this at 08:00 till 10:00
$('#dhuha').addClass(
cls,
(hr >= 8) && (hr < 10)
);
});
It uses toggleClass() which can take a yesOrNo
expression/function as a second param. If it's true, adds the class. If not, it removes it.
Also, your conditions were a bit off. You don't need to check for minutes, since you always apply the class at sharp hour. Pay attention to my conditions, I'm sure they'll make sense.
To see it in action:
$(window).on('load', function(){
let hr = new Date().getHours(),
cls = 'opened';
// I want execute this at 20:00 till 04:00
$('#tahajud').toggleClass(
cls,
(hr >= 20) || (hr < 5)
);
// I want execute this at 04:00 till 06:00
$('#fajr').toggleClass(
cls,
(hr >= 4) && (hr < 6)
);
// I want execute this at 08:00 till 10:00
$('#dhuha').addClass(
cls,
(hr >= 8) && (hr < 10)
);
});
#tahajud span::before,
#fajr span::before,
#dhuha span::before {
content: 'closed for codepen.';
}
#tahajud.opened span::before,
#fajr.opened span::before,
#dhuha.opened span::before {
content: 'openend for codepen.';
color: #382;
}
span {
color: #f50;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="tahajud">Tahajud is now <span></span></div>
<div id="fajr">Fajr is now <span></span></div>
<div id="dhuha">Dhuha is now <span></span></div>