Reputation: 109
Why is this not working on my website? It worked on the code snippet function from stackoverflow
It's exactly the same!
<script>
$("#swipe-product").click(function(){
alert("HELLO");
});
</script>
<div class="text-center" id="swipe-product">
<img src='http://www.borduurfamke.nl/Embirdtips/Embirdlessen/Studio%20les%20Plaatje.jpg' alt='plaatje'>
</div>
Upvotes: -1
Views: 6688
Reputation: 1
I had the same problem. After adding
type = "text/javascript"
to script code my problem solved.
Upvotes: -1
Reputation: 31
Its working for me. You need to add the reference
<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
You can check the Demo
Upvotes: 0
Reputation: 2967
You haven't included jQuery library, if yes, double check the path.
Script runs before jQuery is completely loaded, use $( document ).ready()
function like below, or put the script in the footer.
$( document ).ready() Reference
<script>
$(document).ready(function(){
$("#swipe-product").click(function(){
alert("HELLO");
});
})
</script>
Upvotes: 0
Reputation: 6737
You need a local copy of jQuery or a link to a cdn version of it. The current link you're including is to a relative path within your project so it's looking for a copy of jQuery within your js folder.
You can download jQuery here and place it in that folder, but it might be easier just while you're getting used to it to use a cdn, this means you use a copy of jQuery hosted by someone like Google. It's not always the fastest or most stable method but it's definitely the easiest.
Replace
<script src="/js/jquery-1.11.2.min.js"></script>
With
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
Upvotes: 0
Reputation: 944455
Most likely causes:
ready()
.Upvotes: 1