...

View Full Version : Changing Margins with onClick??



Vizard-Coder
07-29-2010, 05:27 AM
Hello,

I have a div called pageWrap to wrap my page with the css as

margin-top:-46px;

I would like to use Javascript onClick on another div.
This Div is called loginButton, the onclick should change the the css of pageWrap to 0px and onclick again should change it back.

If someone could help me with this code, it would be greatly appreciated

Thanks in advance! :)

Kor
07-29-2010, 03:21 PM
<script type="text/javascript">
onload=function(){
var login=document.getElementById('loginButton');
var target=document.getElementById('pageWrap');
login.onclick=function(){
target.style.marginTop=target.style.marginTop=='0px'?'-46px':'0px';
}
}
</script>


Important: Regarding those DIV's, I hope that by "called" you mean "they have an id".

And a small note: never throw thanks in advance. This is not the Bawdy House :)

Vizard-Coder
07-30-2010, 12:51 AM
Thank you that is exactly what I wanted!

Now it may not be part of this thread but how do I make it so it slides down??
Or is that too complex?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum