/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] JavaScript & CSS – quick question!

I’m using a JavaScript function to change the margin property of a div. I click once and it changes just fine, I click the other button and and it’s supposed to change a back, but doesn’t… in Firefox anyway…

function swapMargin() {
document.getElementById(‘buttons’).style.margin = “0”;
}
function swapBack() {
document.getElementById(‘buttons’).style.margin = “0 250px 0 0”;
}

And the buttons obviously call each function…

The bug is in FF …. seems to set the style once, but wont do it again!

PLEASE HELP!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mrhooMay 13.2008 — Use the same format to reset the margin-

function swapMargin() {

document.getElementById('buttons').style.margin = [B]"0 0 0 0";[/B]

}

function swapBack() {

document.getElementById('buttons').style.margin = "0 250px 0 0";

}
Copy linkTweet thisAlerts:
@KorMay 13.2008 — or, to avoid any misunderstanding, set the margin position:
<i>
</i>function swapMargin() {
document.getElementById('buttons').style.marginLeft = "0";
}
function swapBack() {
document.getElementById('buttons').style.marginLeft = "250px";
}
Copy linkTweet thisAlerts:
@robmarstonauthorMay 13.2008 — Worked perfectly, thanks so much!

In one of my instances I forgot the "x" in "px" -- that may've also been the culprit!
×

Success!

Help @robmarston spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...