-1

enter image description hereI am using sublime-text 2 editör and chromium web browser in Ubuntu.This very simple code not working but when I only write alert("test") within script tags it is working But this simple code not working now.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Scroll Activated Animation</title>
<script type="text/javascript" src="../../jquery-2.1.4.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $("#test").click(function(){
      alert("test");
    });
  });
</script>
<style type="text/css" rel="stylesheet">
    #test{
    width:50px;
    height:50px;
    background-color: #eee;
    margin: 0 auto;
  }
  </style>
</head>
 <body>
  <div id="test">Click here</div>
 </body>
</html>

There is no problem with jquery source code.Because as I told above only alert is working

Image Path:

enter image description here

enter image description here

enter image description here

enter image description here

Tarık Akyüz
  • 97
  • 2
  • 10

2 Answers2

7

Check if the path to jQuery correct. In your case, the path should be this way:

+ jquery-2.1.4.js
+ some_folder
| + some_other_folder
| | + index.html     ----- This is your file.

The code you have given is perfectly right. You have two options:

  1. Correct the path of jQuery.
  2. Use a CDN: http://code.jquery.com/jquery-2.1.4.js

So the second option would be adding the following instead of what you have as a reference for jQuery in your <head>:

<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.js"></script>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
1

I have created a fiddle with your code and it seems to work.

  $(document).ready(function(){
    $("#test").click(function(){
      alert("test");
    });
  });

http://jsfiddle.net/1ygxkx24/

Do you get any error in your browser's command line?

The problem is probably related to the import of the jquery library: the fact that alert works anyway doesn't mean a lot since it's pure js and not jquery related.

nowhere
  • 1,558
  • 1
  • 12
  • 31
  • who the hell is downvoting this answer? Add a comment and help nowhere improve her post if you think it is unworthy... – Zim84 Oct 01 '15 at 10:18
  • 4
    This is not really an answer, more of a request for more information - should probably have been a comment (PS. not my downvote - appears to be gone now) – Jamiec Oct 01 '15 at 10:18
  • I've updated it a bit. He's saying that it should work because the alert works anyway outside of the jquery function. – nowhere Oct 01 '15 at 10:19
  • @nowhere alert dont need jquery. OP problem is Jquery is not working. Maybe path is incorrect. as what Praveen suggested – guradio Oct 01 '15 at 10:21
  • 1
    @Pekka exactly that's what we were trying to explain :) But without the console errors it's hard to debug here... – nowhere Oct 01 '15 at 10:22