0

Hi so I'm trying to like a javascript file to my web page, when it was in the HTML file it worked fine, but I won't to neaten it up a little by putting the JS in a different file HTML:

<head>
<meta charset="utf-8" />
<title>Digital Canvas Web Designs</title>
<link rel="stylesheet" href="/CSS/Template.css"/>
<link rel="stylesheet" href="/CSS/news.css"/>
<link rel="shortcut icon" href="images/tablogo.ico" > <!-- tab logo generated at http://www.favicongenerator.com/ -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="Javascript/newshide.js" type="text/javascript"></script>
</head>
<body>

and Javascript:

<script type="text/javascript">

   $(document).ready(function(){
       $("#show").click(function() {
          $("#hidden").show();
   });

   $("#hide").click(function() {
        $("#hidden").hide();
   });
 });
</script>

And the part of HTML where the JS should work.

<span id="show">more>></span>
<p id="hidden" hidden>COOL STORY BRO
<span id="hide">less</span> </p>
1
  • 2
    Forward slashes on the web. Commented Dec 4, 2014 at 17:27

2 Answers 2

2

wrap all into document.ready

<script type="text/javascript">

$(document).ready(function(){
     $("#show").click(function() {
        $("#hidden").show();
     });

     $("#hide").click(function() {
        $("#hidden").hide();
     });
});
</script>

Also: you have another bug, change the last script for:

<script src="Javascript/newshide.js" type="text/javascript"></script>

Docs

Sign up to request clarification or add additional context in comments.

3 Comments

I tried that but still nothing happens when you click the "more". got any other suggestions, thanks
Yeah the error coming up is "Uncaught SyntaxError: Unexpected token <"
Okay it was because it shouldn't have <script> stuff on it
0

Change this

<script src=".\Javascript\newshide.js" type="text/javascript"></script>

To this

<script src="Javascript/newshide.js" type="text/javascript"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.