maja
maja

Reputation: 187

How to get value transform rotation in javascript?

What is the best way to get transform rotation from some element? How to get variables with "deg" alert (15deg) and how to get without "deg" alert (15) ...

<div id="myElement" style="width: 150px; height: 150px; background:red;  transform: rotate(10deg);"></div>
<button onclick="myFunction()">Try it</button>
function myFunction() {
var angledeg = document.getElementById('myElement').value.transform.??
var angle = document.getElementById('myElement').value.transform.??
       alert(angledeg);"
       alert(angle);
}

Upvotes: 0

Views: 992

Answers (2)

ImranShaik
ImranShaik

Reputation: 31

try this

 #myElement{
    transform: rotate(15deg);
  }

or in Javascript you can try like this

object.style.transform="rotate(15deg)";

Upvotes: -1

Kevin Zhang
Kevin Zhang

Reputation: 1072

Try this code demo:

function myFunction() {
var transform = document.getElementById('myElement').style.transform;
console.log(transform);
}
<div id="myElement" style="width: 150px; height: 150px; background:red;  transform: rotate(10deg);"></div>
<button onclick="myFunction()">Try it</button>

Upvotes: 1

Related Questions