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 7007781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:39:06+00:00 2026-05-27T21:39:06+00:00

What is the most efficient way to set multiple styling on elements in javascript?

  • 0

What is the most efficient way to set multiple styling on elements in javascript?

for (i=0;i<=lastSelector;i++) {
var e = mySelector[i],
v = 'opacity 1s';
e.style.WebkitTransition = v;
e.style.MozTransition = v;
e.style.OTransition = v;
e.style.MsTransition = v;
e.style.transition = v;
e.style.opacity = 0;
};
  • 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-05-27T21:39:06+00:00Added an answer on May 27, 2026 at 9:39 pm

    Pretty much that, you could use a stacked assignment:

    for (i=0;i<=lastSelector;i++) {
      var e = mySelector[i];
      e.style.WebkitTransition =
        e.style.MozTransition =
          e.style.OTransition =
            e.style.MsTransition =
              e.style.transition =
                'opacity 1s';
      e.style.opacity = 0;
    }
    

    Since there are several of these properties where we have vendor-specific versions, you might consider a reusable function that does this, e.g.:

    function setMultiVendorProp(style, propName, value) {
        // Set the non-vendor version
        style[propName] = value;
    
        // Make first char capped
        propName = propName.substring(0, 1).toUpperCase() + propName.substring(1);
    
        // Set vendor versions
        style["Webkit" + propName] = value;
        style["Moz" + propName] = value;
        style["O" + propName] = value;
        style["Ms" + propName] = value;
    
        // Done
        return value;
    }
    

    Or using the dashed style instead, since we’re already using strings rather than identifiers:

    function setMultiVendorProp(style, propName, value) {
        // Set the non-vendor version
        style[propName] = value;
    
        // Set vendor versions
        style["-webkit-" + propName] = value;
        style["-moz-" + propName] = value;
        style["-o-" + propName] = value;
        style["-ms-" + propName] = value;
    
        // Done
        return value;
    }
    

    Then:

    for (i=0;i<=lastSelector;i++) {
      var e = mySelector[i];
      setMultiVendorProp(e.style, "transition", "opacity 1s");
      e.style.opacity = 0;
    }
    

    Side notes:

    • There’s no ; after the closing } in a for statement.
    • var anywhere in a function is function-wide, so declaring var within non-function blocks inside the function is (slightly) misleading to the reader of the code; details: Poor, misunderstood var
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the most efficient way to set/re-order the TabIndex properties of many form
What would be the most efficient way to set customized formatting of the column
Given a large sorted set with rapidly changing scores/weights, what's the most efficient way
What's the best/most efficient way to extract text set between parenthesis? Say I wanted
I'm looking for the most efficient way to be able to set some basic
I am trying to find the most efficient way of running multiple (> 1000)
What is the most efficient way to drop a table in SAS? I have
What is the most efficient way for checking for equality of two m *
What's the most efficient way to sort objects in an NSSet / NSMutableSet based
What is the fastest / most efficient way of getting all the distinct items

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.