title: jQuery .css("margin-left")
body: <p>I made a kind of game in javascript and in this game there are some divs which are horizontally moving with different transition times. In this game there is a function which is called each <code>1/100</code> seconds. Then it first checks it position with: </p>
  
  <pre><code>$("class1").css("margin-left") 
  </code></pre>
  
  <p>And now the weird thing: when I set the class in html like: </p>
  
  <pre><code>&lt;div class = "class1"&gt;&lt;/div&gt; 
  </code></pre>
  
  <p>The <code>.css("margin-left")</code> works perfectly, but when I don't set a class in html and I add the class in js like: </p>
  
  <pre><code>$("div:nth-child(6)").addClass("class1");
  </code></pre>
  
  <p>Then the <code>$(theclass).css("margin-left")</code> give wrong outputs.
  I tried with the .position and .offset but those both didn't work for me.</p>
  
  <p>My code:</p>
  
  <pre><code>function newBlock(block, marginTop, bgc, height, hoogte1, hoogte2, v, tijd){
                          block.css("background-color", bgc).css("height", height).css("margin-top", marginTop);
                          var movement1 = "movement1";
                          var movement2 = "movement2";
  //                        if (positionPixelsBlockF &gt; 0){
  //                            positionPixelsBlockF = positionBlockF.slice(0, 3);
  //                        }
                          setInterval(positie, 10);
                          function positie(){
                          tijd = tijd + 1;
                          if (v != 0){
                              block.addClass("i" + v);
                              $(".i" + v).css({"width": "50px", "display": "inline-block", "position": "absolute", "z-index": "20"});
                              var positionBlockF = $(".i" + v).css("margin-left");
                              var positionPixelsBlockF = positionBlockF.slice(0, 4);
                              $("#uitleg4").html(positionPixelsBlockF);
  else if (v === 0){
                              var positionBlockF = $(".b1").css("margin-left");
                              var positionPixelsBlockF = positionBlockF.slice(0, 4);
  </code></pre>
  
  <p>Don't mind the incomplete use of the {}, but in my code that's fixed.</p>
  
  <p>PS: using brackets</p>