1

Okay so, I'm not a complete noob but still a beginner at jQuery/javascript and I'm just not getting why this jqueryman.js isn't linking to my html. I am pretty sure i have got the folders tree right, i even placed my js file in the same folder as my html just to make sure it wasn't a mistake there.

head of the index.html

<!-- metas -->
<meta charset='UTF-8'>
<!-- stylesheets -->
    <link rel='stylesheet' href='../css/mainpage.css'>
    <link rel='stylesheet' href='../css/index.css'>
<!-- all the scripts loosly taken online -->
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
    <script src='http://malsup.github.com/jquery.cycle2.js'></script>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
<!-- script files -->
    <script src="jqueryman.js"></script>    <!-- (this is the trouble maker) -->

body of the index.html

<h1 class="h1">neckbeards</h1>


<div class='cycle-slideshow'
    data-cycle-fx='scrollHorz'
    data-cycle-pause-on-hover='false'
    data-cycle-speed='5000'>
    <img class='sliderimg' id="Carl"    alt='Carl'      src='http://i.imgur.com/7kJOy7k.jpg'>
    <img class='sliderimg' id="Tugboat" alt='Tugboat'   src='http://i.imgur.com/mRGbOKv.jpg'>
    <img class='sliderimg' id="P0J0"    alt='P0J0'      src='http://i.imgur.com/UiAIWGf.png'>
    <img class='sliderimg' id="Ffej"    alt='Ffej'      src='http://i.imgur.com/isl6UhR.png'>
</div>
<h1 id="name">Carl</h1>

jqueryman.js

 $(document).ready(
        function () {
            $('.h1').hide()
        });
    );
10
  • If you could post the error from your console that would be beneficial. also try added the code to jsfiddle.net and updating your answer with the link. Commented Jan 4, 2014 at 20:12
  • You are trying to load 2 versions of jquery at the same time: the one from google and the one from jquery. Lose one of them. Just make sure the jquery plugin you're using is called after jquery. Also check jquery is loading properly by loading your page in firefox, > view source click the jquery link. If you see the code you've loaded it correctly. If not check the path. Commented Jan 4, 2014 at 20:14
  • Also lose the last closing paren in your own code. Commented Jan 4, 2014 at 20:16
  • jsfiddle.net/MG62E strangly enough this does work.. then I just linked it in a wrong way but it's in the same map.. Commented Jan 4, 2014 at 20:19
  • Heres a working fiddle jsfiddle.net/xQ9yE Commented Jan 4, 2014 at 20:23

6 Answers 6

2

UPDATE: Heres is working example: JSFiddle
You need to remove the . from $('.h1').hide(); The . is referring to a class but you just want to hide the base h1 element.

$(document).ready(function () {
    $('h1').hide();
});

Alternatively to hide just that one element you can do it by its ID.

$(document).ready(function () {
    $('#name').hide();
});

Heres a link to jQuery Selectors tutorial.

Also as noted from comments you also have a syntax error in your JavaScript.

$(document).ready(
    function () {
        $('.h1').hide() // As with both my example above you need to add a semicolon 
    });
); // Additional brace & semicolon that would cause a syntax error.
Sign up to request clarification or add additional context in comments.

4 Comments

thank you altho i have a class called h1. and it still wont work with or without the .
@user2997422 sorry i didn't see that, I have added a comment to your Question
jsfiddle.net/MG62E strangly enough this does work.. then I just linked it in a wring way but it's in the same map..
but yout jsfiddle isn't working on my pc for some odd reason? xs the jsfiddle i posted worked but not whilst actually putting it in a browser
2

Your current jQuery code:

 $(document).ready(
     function () {
          $('.h1').hide()
     });
 );

is not using correct syntax. (You have an extra ); at the end).

Try this:

 $(document).ready(function() {
     $('.h1').hide();
 });

Comments

1

Remove the . from h1...

$('h1').hide()

Dots are for classes. So if you have a something like this:

<h1 class='myh1'>

you use $('.myh1') to access it. But if you are talking about a tag, h1, h2, a, img, div, span, you do not use dots.

Interestingly, you can (but shouldn't) even do this in most browsers:

<panda>hello</panda>

and then access it with

$('panda')

Because that isn't a class, but rather a non-standard tag.

4 Comments

Explain why for the asker
thank you altho i have a class called h1. and it still wont work with or without the .
@user2997422 could you post on jsfiddle.net and update your question with the link
jsfiddle.net/MG62E strangly enough this does work.. then I just linked it in a wring way but it's in the same map..
1

I have tested this locally and it works for me -- even with the two issues mentioned below:

(1) You have a syntax error. Remove the extra ); from the end of the script.

$(document).ready(
    function () {
        $('.h1').hide()
    });
);  // <--- This is not needed.

(2) You are including jQuery twice:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
...
<script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>

2 Comments

thanks but sadly it still isn't working I'm afraid xs
@user2997422 - Sorry, I thought this was the issue because I tested it in a jsfiddle, and this syntax error prevented it from working.
0

As a rule I would avoid creating a class name the same as a tag name. I think this adds confusion if other coders were to look at the javascript code and not have the html immediately on hand to look at.

1 Comment

I try to do this but I was just doing it for testing purposes, I'll take causion next time.
0

I found the solution and there is no problem with the class name.

use this it will work because you only forgot the semicolon(;) :

$(document).ready(function () {
    $('.h1').hide();
});

3 Comments

Thank you sooo much man, I tried it before but it wasn't working but you sir are amazing, thank you SO much <3
sorry ashley, I'm very new to this website and the layout is still confusing to me. please forgive me? :s
@JohnS I think the semicolon maters because it shows the end of the statement.

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.