Reputation: 338
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
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
Reputation: 385
$("this").animate({
marginLeft: "+=250px",
}, 1000 );
should be changed to:
$(this).animate({
marginLeft: "+=250px",
}, 1000 );
"this" -> this
Upvotes: 1