1

I tried opening the following code in both FF and chrome, nothing happened. But when I loaded the exact code in jsfiddle, it worked .

jsfiddle link

HTML:

<!doctype html>

<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="fgerg.css" />
<script type="text/javascript" src="jquery-1.7.2.js"></script>


<script type="text/javascript">
                $(document).ready(function() {



                    $('#showButton').click(function() {
                        $('#x2').css('visibility','visible');


                    });     
                });​

            </script>   
</head>

<body>
 <input type="button" id="showButton" value="show" />
    <p id="x"> gergreg</p>
    <p id="x2"> sadeijnfciu </p>        
</body>
    </html>

CSS:

#x {
display:none;
 }

 #x2 {
visibility: hidden;
}

For anyone interested, the rectangle after the last }); caused the whole mess. Anyone know what is that ? Wierd special character

TheKraven
  • 583
  • 2
  • 8
  • 23
  • I found this error in the error console : Which part is it illegal ? `Uncaught SyntaxError: Unexpected token ILLEGAL ` – TheKraven Aug 14 '12 at 13:55

5 Answers5

2

The javascript code looks valid.

Are you sure that the jquery-1.7.2.js file is in the same directory as your index.html ?

+my webpage
-----jquery-1.7.2.js
-----index.html
-----.......

does your directory look like this ?

I would recommend you to use the jQuery libary hosted by google like so:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
mas-designs
  • 7,498
  • 1
  • 31
  • 56
2

The error: Uncaught SyntaxError: Unexpected token ILLEGAL normally means you have some weird encoded character somewhere in your page/JavaScript source. Best bet is to either open the files up editor with it showing special characters, or to create a new file and copy in sections of the code.

Community
  • 1
  • 1
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • OMG. There's in fact one never-seen-before double rectangle special character in my javascript code.. Wth ? It has been making me tear my hair out all day. Thanks alot. – TheKraven Aug 14 '12 at 14:10
1

Most likely your link to jquery is broken or you are using a corrupted version. Try including jQuery from a CDN instead:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> 

Instead of

<script type="text/javascript" src="jquery-1.7.2.js"></script>
Rondel
  • 4,811
  • 11
  • 41
  • 67
  • +1 for the google hosted lib ;-) – mas-designs Aug 14 '12 at 13:46
  • I am using localhost, the google host should still work right ? I tried the Google host, the result is still the same. Is there a possibility that the issue is with my laptop ? – TheKraven Aug 14 '12 at 13:47
  • It should work fine `localhost`. If you aren't getting any javascript errors, then make sure that all your IDs are correct. It may be worth it to debug in **Firebug** to see if the function is even being called. – Rondel Aug 14 '12 at 13:54
0

Unless you have a specific reason for using visibility i would prefer to use .show() instead: http://jsfiddle.net/Nuh9w/3/

Alex
  • 8,875
  • 2
  • 27
  • 44
0

When you are running the code in FF or Chrome, do you have the jQuery file that is being referenced in the same relative path as the HTML file? When you are doing this in jsfiddle, the jQuery library is being loaded by the jsfiddle site.

mccrager
  • 1,038
  • 6
  • 13