Reputation: 217
The following code doesn't seem to work. How would I change it in order to make the div change the position from top?
div { width:220px; height:170px; margin: 10px 50px 10px 10px;
background:yellow; border:2px groove; float:right; }
#alt { width:20px; height:170px; margin: 10px 50px 10px 10px;
background:blue; border:2px groove; float:right; }
#altLevel { width:10px; height:20px;
background:red; border:2px groove; }
$('div').mouseclick(function() {
$( '#altLevel').css( 'top', '+=10' );
});
Upvotes: 2
Views: 5473
Reputation: 92913
You have to add position:absolute
or position:fixed
to the styles for #altLevel
before you can alter its position. In addition, give it a default position of top:0
or whatever you like:
#altLevel {
width:10px; height:20px;
position:absolute; top:0;
background:red; border:2px groove;
}
Once you do that, your JavaScript should work with a small modification:
$('div').click(function() {
$('#altLevel').css('top', '+=10');
});
http://jsfiddle.net/mblase75/mGAKe/
Upvotes: 2