Sam Murphey
Sam Murphey

Reputation: 338

Moving a div with animation

I'm looking to move a div "#menu" to the side when it's clicked on. I'm using this code

  <script>
    $("#menu").click(function(){
        $("this").animate({ 
            marginLeft: "+=250px",
        }, 1000 );
    });
    </script> 

but it doesnt seem to do anything, I dont even get a cursor when I hover over it. What am I doing wrong here? I'm sure this is a simple fix that I'm just overlooking.

Upvotes: 2

Views: 93

Answers (3)

Lix
Lix

Reputation: 47956

You should use $(this) (without quotes).

$("#menu").click(function(){
  $(this).animate({ 
    marginLeft: "+=250px",
  }, 1000 );
});

When you use it with quotes it's as if you are trying to match a <this></this> element on your document. I'm fairly sure that's not what you want :)

Upvotes: 4

svobol13
svobol13

Reputation: 1950

Try to remove quotation marks $(this).

Upvotes: 1

Diomedes Andreou
Diomedes Andreou

Reputation: 385

 $("this").animate({ 
        marginLeft: "+=250px",
    }, 1000 );

should be changed to:

 $(this).animate({ 
        marginLeft: "+=250px",
    }, 1000 );

"this" -> this

Upvotes: 1

Related Questions