Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:14:40+00:00 2026-06-15T15:14:40+00:00

If you have an element with many values for transform how do you change

  • 0

If you have an element with many values for transform how do you change just one of those values without changing the other values?

You could rewrite them every time but in some situations that means you will have to parse apart the css for the transform into its different parts. For example:

-webkit-transform:rotateY(45deg) rotate(45deg);

you would have to get the property and value for rotate and rotateY. Isn’t there a way to get and set just rotate without changing the value for rotateY?

The problem is illustrated here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:14:41+00:00Added an answer on June 15, 2026 at 3:14 pm

    There is no way to directly modify a single component of the transform. Sadly, the various possible transforms were implemented as values on the transform attribute, rather than attributes themselves. There is no object model for CSS attribute values – attribute values are always just a string, as far as JavaScript is concerned. It would’ve been nice if transform was treated as a shorthand attribute for, eg, transform-rotate-y, transform-*, etc, the same way that background is a shorthand attribute for all the background-* attributes. This would’ve allowed us direct access to the values via JavaScript, but it was not implemented that way, so we are out of luck.

    Edit: The simplest way to accomplish this (without studying the spec and doing a bunch of math) would be to nest your elements, applying different transformations to each. If you apply several transformations that won’t change, go ahead and combine those on to one element. Any transformation that you do want to change, use a separate element:

    Works here: jsfiddle.net/mkTKH/15


    Edit: My original solution below won’t work. In testing it out I discovered that getComputedStyle() converts the transform into a matrix(). An early draft of the spec says:

    The transform property of the style object returned by getComputedStyle contains a single CSSTransformValue with a type of CSS_MATRIX. The 6 parameters represent the 3×2 matrix that is the result of applying the individual functions listed in the transform property.


    So, you have to parse it. If you want to change just one portion of an attribute value, you can use a regular expression to parse the value:

    var rotateY = "rotateY(" + deg + "deg)";
    var transform = el.style.webkitTransform.replace(/\brotateY([^)]+)\b/, rotateY);
    el.style.webkitTransform = transform;
    

    I’d create a reusable function:

    function setTransformValue(el, name, value) {
        var currentValue = new RegExp(name + "([^)]+)");
        var style = window.getComputedStyle ? getComputedStyle(el) : el.currentStyle;
        var currentTransform = style.transform ||
                               style.webkitTransform ||
                               style.MozTransform ||
                               style.msTransform ||
                               style.OTransform;
        var transform;
        if (currentValue.test(currentTransform )) {
            transform = currentTransform.replace(currentValue, name + "(" + value + ")");
        }
        else {
            transform = currentTransform + " " + name + "(" + value + ")";
        }
        el.style.transform = transform;
    }
    

    Untested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DOM element like this: <div id='master-value'>Apples</div> I have many other elements
There are many functions within the code I am maintaining which have what could
Problem is next - i have 2 entities with one-to-many relationships: public class Schema
(I've looked at many other similar posts on SO and have unfortunately not been
I'm using XPath to pull out just the values of URL128 XML element. There
I have some query regarding tableViewCell . There are many values added in an
I have some users that can have many posts , and each of those
I'm developing an Jquery plugin and have to set many css values inside of
There are two tables, which have a relationship(one-to-many). There are Meals table which contains
i have a json file with many elements like these: { code : hfuiew89,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.