So I have a Wordpress blog that needs to show a div with class .exp-col-content-holder the first time a user visits.
I've been reading around, and I understand the concept of setting a cookie with Javascript, but in practice it doesn't seem to be working. I've pared away my code, and not even my selector is selecting.
Here's the code I'm using to change the style of the div from display:none to display:block
<script type="text/javascript">
var element = document.getElementsByClassName('exp-col-content-holder');
element.style.display = 'block';
</script>
Even that does not seem to work when it runs on the page. The code to actually register whether a person has visited before, (and run the code if they haven't) is this:
<script type="text/javascript">
var cookie = document.cookie;
if (cookie.indexOf('visited=', 0) == -1) {
var expiration = new Date();
expiration.setDate(expiration.getDate()+100);
document.cookie = 'visited=1;expires=' + expiration + ';path=/';
var element = document.getElementsByClassName('exp-col-content-holder');
element.style.display = 'block';
}
</script>
Where am I going wrong? I've tried moving the code different places in the page, etc... all to no avail.