Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

getcomputed style js

// This method return an object including all css properties of an object
// Code below moves an element with id = element to the right
// on every button click, assuming a position relative for element. 
const button = document.querySelector("button");
const targetElement = document.getElementById("element");

button.addEventListener("click", moveRight);

function moveRight() {
  const { left } = getComputedStyle(targetElement);
  targetElement.style.left = parseInt(left) + 10 + "px";
}
 
PREVIOUS NEXT
Tagged: #getcomputed #style #js
ADD COMMENT
Topic
Name
9+3 =