Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 226
M21 Avatar asked Dec 18 '22 15:12

M21


1 Answers

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";
}
like image 189
Jamiec Avatar answered Jan 04 '23 01:01

Jamiec