0

Thank you in advance for any assistance. I'm having difficulty completing a very simple case of the addClass method. I've read a bunch of resources and still can't figure it out. Any idea why this wouldn't work?

<html>
    <head>
        <style>.blueright {color:blue;}</style>
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>

        <h4 id="test">asdf</h4>
        <script> $("#test").addClass("blueright"); </script>
    </body>
</html>

What am I doing wrong? Thank you again! -Dan

5
  • Working jsfiddle.net/cse_tushar/72mN7 Commented Feb 14, 2014 at 17:23
  • just fine plnkr.co/edit/xKvXBv3pIc38KzKGwmCq?p=preview Commented Feb 14, 2014 at 17:25
  • How are you opening the file? Commented Feb 14, 2014 at 17:26
  • are you loading the file using a file:// url - loading the file from local file system instead of from a web server Commented Feb 14, 2014 at 17:26
  • This code is fine on the web, if you're testing on local machine you're not giving it the right address. Add an http:// in there, or just wait until you have it on the web and it will be fine. Commented Feb 14, 2014 at 17:31

1 Answer 1

1

Working Fiddle

your code is working good.


Problem is with jQuery library loading

Try script URL

<script src="//code.jquery.com/jquery-1.10.2.js"></script>

change with

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>


Browser takes //code.jquery.com/jquery-1.10.2.js it as

if your working on local pc than it will take is as file://code.jquery.com/jquery-1.10.2.js"

but on server it takes it as http://code.jquery.com/jquery-1.10.2.js"

So better use <script src="http://code.jquery.com/jquery-1.10.2.js"></script>

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.