Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Help estar using jQuery

Hi, lads, as you'll see, I'm start learning jQuery...

I'm just experimenting with simple stuff, so I just set up a very simple html document to add some effects to a li elements... how ever, I just can't make it work...

Maybe is something really simple, but can't see what I'm doing wrong...

Can you guys, take a look an tell me if you see something wrong?

The thing I that when I launch the index.html doc in the browser don't see any jqery applied when clicking the li element.

This is the index.html:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css" />
        <script src="jquery.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js">     </script>
        <script src='script.js'></script>
        <title>Basti lobo de Baby</title>
    </head>
    <body>
        <div class="wrapper">
            <div class="memoria">
                <ul>
                    <li class="item">
                        <img src="images/3.jpg"></img>
                    </li>
                    <li class="item">
                        <img src="images/8.jpg"></img>
                    </li>
                    <li class="item">
                        <img src="images/10.jpg"></img>
                    </li>   

                    <li class="item">
                        <img src="images/5.jpg"></img>
                    </li>
                    <li class="item">
                        <img src="images/6.jpg"></img>
                    </li>
                    <li class="item">
                        <img src="images/7.jpg"></img>
                    </li>
                    <li class="item">
                        <img src="images/9.jpg"></img>
                    </li>

                    <li class="item">
                        <img src="images/12.jpg"></img>
                    </li>

                    <li class="item">
                        <img src="images/1.jpg"></img>
                    </li>

                    <li class="item">
                        <img src="images/2.jpg"></img>
                    </li>

                    </li class="item">
                        <img src="images/4.jpg"></img>
                    </li>

                    <li class="item">
                        <img src="images/11.jpg"></img>
                    </li>
                </ul>
            </div>
        </div>
     </body>
</html>

this is the css:

.wrapper{
    width: 800px;
    margin-left: auto;
    margin-right:auto;
}

img {
    width: 200px;
    height: 200px;
}

.memoria {
    text-align: center;
    display: inline
}

li {
        display:inline-block
}

and this is the script

$(document).ready(function(){
    $("item").click(function(){
        $(this).fadeTo("slow", .05);
    });
});

5 Answers

You need to change $("item") to $(".item") in your script.

You just forgot the (.) period for your class.

Remember to use a (.) period to identify your classes and a (#) pound-sign to identify your IDs in your HTML/Javascript.


Correct me if I am wrong people, but I think it is better to use IDs when performing things like "click.'

@Joseph - With CSS is most cases it's better to use classes over IDs for specifity reasons. With JQuery the only difference is if you are writing high performance JQuery IDs are faster.

@James Great information!


@Alejandro

Did you have any luck with your code?

Guys, thanks a lot!

Yes, @Joseph, so simple and I didn't see it! upssss...

Thanks!

@Alejandro

Lol, those little things slip passed us sometimes!

Best of luck to you!