JavaScript Escape “” characters to enter variable in jQuery escape characters enter

I am sure this one is staring me in the face. Trying to increase the rotation on an object until i reaches a value. Getting an error as I am trying to escape the CSS part to enter my variable 'i'.

Can anybody see what may be wrong?

for(var i = 0; i < 200; i++){
  console.log(i);
  $('.rotateMe').css({"transform": "rotate("i"deg)"});
}

Thanks

Answer:1

You have to concatenate variable inside string with + , like this:

for(var i = 0; i < 200; i++){
  console.log(i);
  $('.rotateMe').css({"transform": "rotate("+i+"deg)"});
} 

for (var i = 0; i < 200; i++) {
  $('.rotateMe').css({
    "transform": "rotate(" + i + "deg)"
  });
}
.rotateMe {
  width: 50px;
  height: 50px;
  background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="rotateMe"></div>
Answer:2

You forgot the +

 for(var i = 0; i < 200; i++){
    console.log(i);
    $('.rotateMe').css({"transform": "rotate("+i+"deg)"});
 }
Answer:3

You cannot concatenate strings like that in JS, try

"rotate("+i+"deg)"
Answer:4

I have a owl carousel with 3 items, the carousel displays one item per page. Inside each item I have html inputs. I want to programmatically change the active item so I can make focus on input inside ...

I have a owl carousel with 3 items, the carousel displays one item per page. Inside each item I have html inputs. I want to programmatically change the active item so I can make focus on input inside ...

  1. get active item owl carousel
  2. owl carousel active item
  3. owl carousel center active item
  4. owl carousel active item bigger
  5. owl carousel first item active
  6. owl carousel set active item
  7. owl carousel active item css
  8. owl carousel 2 get active item
  9. owl carousel change active item
  10. owl carousel active item index
  11. owl carousel 2 active item
  12. owl carousel active item class
  13. owl carousel 2 set active item
  14. owl carousel active item left
  15. owl carousel get active item index
  16. owl carousel active item width
  17. owl carousel last active item
  18. owl carousel only one item active
  19. owl carousel find active item
  20. owl carousel 1 active item

Anyone managed to use ng-class for placing dynamic base64 encoded images as background-images for a div yet? Seems to work for JQuery (see Is there a way to set background-image as a base64 encoded ...

Anyone managed to use ng-class for placing dynamic base64 encoded images as background-images for a div yet? Seems to work for JQuery (see Is there a way to set background-image as a base64 encoded ...

  1. angularjs class dynamic
  2. angularjs dynamic class name
  3. angularjs dynamic class attribute
  4. angularjs dynamic class change
  5. angularjs ng-class dynamic
  6. add class angularjs dynamic
  7. angularjs set dynamic class
  8. angularjs ng-class dynamic class name

I am Implementing push notification in ionic using this tutorial: http://devdactic.com/ionic-push-notifications/ I have succesfully done using this. I got device token: like: Got token: DEV-...

I am Implementing push notification in ionic using this tutorial: http://devdactic.com/ionic-push-notifications/ I have succesfully done using this. I got device token: like: Got token: DEV-...

I have an empty-star button like this, <button type="button" class="btn btn-default btn-lg" id="refresh"> <span class="glyphicon glyphicon-star-empty"></span> </button> ...

I have an empty-star button like this, <button type="button" class="btn btn-default btn-lg" id="refresh"> <span class="glyphicon glyphicon-star-empty"></span> </button> ...