M21 M21 - 4 months ago 21
jQuery Question

show / hide div can do without jquery?

I have a script that is now working, but there's still conflict with other scripts on page that I have no control over... (hosted e-com site with limited access) - is there a way to accomplish this, but with plain javascript?

var $b = jQuery.noConflict(true);

var d = new Date();
var dayOfWeek = d.getUTCDay();
var hour = d.getUTCHours();
var mins = d.getMinutes();
var status = 'open';

if (dayOfWeek !== 6 && dayOfWeek !== 0 && hour >= 12 && hour < 22)
status = 'open';
else
status = 'closed';

if (status=='open')
$b('.orderby').show();
else
$b('.orderby').hide();



Answer

You only have 1 tiny bit of jquery in your code

if (status=='open') {
    $b('.orderby').show();
}else{
    $b('.orderby').hide();
}

This can be converted to

if (status=='open') {
    document.querySelector('.orderby').style.visibility = "visible";
}else{
    document.querySelector('.orderby').style.visibility = "hidden";
}