user176105
user176105

Reputation: 221

Change CSS Property with Jquery Variable

Im trying to use Jquery to change css. The css property is kinda complicated so I'm not sure if my concatination is working or if there's another problem:

JQUERY:

$(document).ready(function() {

var degrees = Math.floor(Math.random() * 151) + 20;  //this is my variable

$('#p2').css("-webkit-transform","rotate("+degrees"deg)");
// this -webkit-transform: rotate(50deg); is the property im trying to change
});

Upvotes: 0

Views: 97

Answers (1)

Sushil
Sushil

Reputation: 2835

there's a small mistake. you're not appending it properly. notice the '+' after the degrees

$(document).ready(function() {

var degrees = Math.floor(Math.random() * 151) + 20;  //this is my variable

$('#p2').css("-webkit-transform","rotate("+ degrees +"deg)");
// this -webkit-transform: rotate(50deg); is the property im trying to change
});

Upvotes: 1

Related Questions