2

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' );
});

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.