I have implemented a script that reads the current page's URL, checks for a specific string, and then creates a cookie with a one-day expiration. If the cookie is present, I hide four divs by their IDs using display = none. The code below is functional, but I am experiencing some slowness as the divs are briefly visible before disappearing.
I have attempted to use jQuery to hide the divs as well as the "document.getElementById .style.display = 'none';" method.
<script type="text/javascript">
var myvariab1= window.location.href;
if( myvariab1.indexOf('thetextiamsearhing') >= 0){
var date = new Date;
date.setDate(date.getDate() + 1);
var mexpire = "; expires="+date;
final_cookie = "mycookie =" + myvariab1+mexpire +"; path=/";
document.cookie = final_cookie;
}
if (document.cookie.indexOf('mycookie') > -1 ) {
$(document).ready(function(){
$('#myid1').hide();
$('#myid2').hide();
$('#myid3').hide();
$('#myid4').hide();
});
}
</script>
How can I optimize this script for faster performance?
The script is located just before the </head>
tag.
It is embedded within an ecommerce script that utilizes jquery.