Jump to content

JQuery Question

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Edu

Edu

    Newbie

  • Members
  • Pip
  • 7 posts
Hi

I am just starting to practice some programing these days and i wanted to mix it up a little so i asked a friend of mine who studies Computer Science and told me to look into Javascript and Jquery.

I read some tutorials but i am not sure of one, very beginner, thing.

when you type in $(document).ready(function(){
Can you do more then one thing inside it or does every JQuery function need a separate $(document)... ?

For example:

$(document).ready(function(){

$("a").click(function() {

	alert("Hello World!");

	});


$("#orderedlist").addClass("red");

	});


})


It didn't work for me but i was wondering maybe i made a mistake somewhere or i just can't do it that way?

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Yes, it can do as much as you want. You can even call it more than once if you'd like. There was not a problem with your code, if it was out of context, however you did have two extra brackets at the end.
<html>
<head>
    <title>jQuery</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("a").click(function() {
                alert("Hello World!");
            });
            $("#orderedlist").addClass("red");
        });
    </script>
</head>
<body>
    <a href="#">Click me!</a>
    <ul id="orderedlist">
        <li>One</li>
        <li>Two</li>
    </ul>
</body>
</html>
http://img80.imagesh...9493/workkc.jpg

For debugging most browsers offer a error console. IE has a yellow thing at the bottom left you can double click to see errors, and Firefox has an "Error Console" at "Tools" -> "Error Console" or "CTRL+SHIFT+J". Hope it helps!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users