1

I have a problem with javascript. I need to change a div's class dynamically using .classeName = "..." but it doesn't update itself. For example, I have put a transform into my class. It does a scale and set the transform-origin but nothing appears on my screen. Here's my code:

var panier = document.getElementById("panier");

if (panier.style.display == "none" || panier.style.display == "")
{
    panier.className = "";
    panier.style.display = "block";
    panier.style.webkitTransform = "scale(0, 0)";
}

if (panier.className.search("enleverPanier") >= 0)
    panier.className += panier.className.replace("enleverPanier", "afficherPanier");
else
    panier.className += " afficherPanier";

As you can see, my class afficherPanier does a scale(1,1). The div keeps it's scale(0,0) that I set in case the div isn't visible.

Here's my css

.afficherPanier {
 -webkit-transform-origin: left top;
 -moz-transform-origin: left top;
  -ms-transform-origin: left top;
   -o-transform-origin: left top;
      transform-origin: left top;

 -webkit-transform: scale(1, 1);
 -moz-transform: scale(1, 1);
 -ms-transform: scale(1, 1);
 -o-transform: scale(1, 1);
    transform: scale(1, 1);}

Do you know why the scale(1,1) doesn't work? Thank you! :)

2
  • transform is not supported in all browsers. Use a browser's web inspector to see if the class is being applied as expected, rather than relying on a visual result. Commented May 17, 2014 at 2:05
  • Sorry, I was confused by a suggested edit. They were all there before the edit. Commented May 17, 2014 at 2:07

1 Answer 1

1

Right now I'm pretty sure className is being changed to enleverPanierafficherPanier. To fix this, try changing

panier.className += panier.className.replace("enleverPanier", "afficherPanier");

to

panier.className = panier.className.replace("enleverPanier", "afficherPanier");
Sign up to request clarification or add additional context in comments.

5 Comments

Oh thanks! I didn't see that, but I still have the same problem: scale(1,1) doesn't do anything.
In that case, would you mind sharing your code (CSS, Javascript, AND HTML) on jsfiddle and posting it here? It would be extremely helpful.
When I put it on jsfiddle, the page is totally broken. :(
Anyway, here's the source code (with no meta/include) jsfiddle.net/thecheeselover/p2Kqa
And by the way, to hide the second page (with the size(0,0)) you need to call HidePanier()

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.