Simple JavaScript Assistance needed.

2 replies
Hey Warriors,

I am new to Javascript and want to implement something which I think should be somewhat simple on my website. I have a link to my webpage below which I am testing on.

I am attempting to have a div appear afte the user starts scrolling.

Link to test page: Test 1 |

For my html I have:
Code:
<div id="mydiv">test div</div>
In my header file I have:
Code:
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/test1.js">
</script>

In my .js file I have:
Code:
$(window).scroll(function() {
    if ($(this).scrollTop() == 0) {
        $("#mydiv:visible").hide();
    }
    else {
        $("#mydiv:hidden").show();
    }
   });
I am getting this error on the page: Uncaught ReferenceError: $ is not defined

So I am not 100% sure why the error is there, and I am not 100% sure that my javascript is correct. It is a wordpress site if that matters.

Please please help me out. Thank you so much for your time, and sorry if this is a novice mistake.
#assistance #javascript #needed #simple
  • Profile picture of the author mikeonrails
    The $() syntax is not pure javascript. It is from a library called jQuery. Try adding this line before your code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    {{ DiscussionBoard.errors[8302274].message }}
    • Profile picture of the author jleavitt13
      Thanks, that fixed it.
      {{ DiscussionBoard.errors[8304572].message }}

Trending Topics