Linked Questions
26 questions linked to/from How can I set multiple CSS styles in JavaScript?
0 votes
3 answers
3k views
Multiple Style Attributes in Javascript [duplicate]
I have to apply multiple styles for a element, currently I have document.getElementById("element1").style.top="1px"; document.getElementById("element1").style.marginLeft="0px"; | | | document....
2 votes
2 answers
241 views
How to apply more than 1 CSS styles in javaScript? [duplicate]
I want to apply more than 1 CSS styles to the button (its id is name_button). Here is my javaScript code. var name_button = document.getElementById('name_button'); name_button.style.display = '...
0 votes
1 answer
437 views
How to set border styles for right, bottom and left in one statement [duplicate]
I want to set the border property of an element on the right, bottom and left only without the top, so I am doing it in three lines like this: document.getElementById("...
0 votes
0 answers
47 views
Adding style in javascript [duplicate]
I have a question how will I make this code as one line. document.getElementById("messageBodyView").style["background-color"] = "#ffffff"; document.getElementById("messageBodyView").style["border"] = ...
0 votes
1 answer
46 views
How to apply string styles to HtmlElement? [duplicate]
I have tried this way to join all styles in string: pointElement.style = ` display: 'block', left: ${(rotated_x + w / 2) / scale}px, top: ${(h / 2 - rotated_y) / scale}px`; It is not ...
400 votes
18 answers
417k views
How to dynamically create CSS class in JavaScript and apply?
I need to create a CSS stylesheet class dynamically in JavaScript and assign it to some HTML elements like - div, table, span, tr, etc and to some controls like asp:Textbox, Dropdownlist and datalist. ...
17 votes
6 answers
29k views
How to convert a JSON style object to a CSS string?
I wanted to set my element's style as such: this.refs.element.style = { ...this.props.style, background: 'blue', }; But apparently you can't use an object to set the ref's style. I have to ...
9 votes
7 answers
27k views
Add Multiple Styles with JavaScript
I want to add multiple lines of CSS with JavaScript. I know I can do this: document.getElementById(id).style.property=new style as in: <!DOCTYPE html> <html> <body> <h1 id="id1"...
5 votes
3 answers
13k views
How do i use 'cssText' in javascript?
I got an error message "Uncaught TypeError: Cannot set property 'cssText' of undefined" My Code: var div = $('.postImg2') var img = $('.postInner2'); var divAspect = 20 / 50; var imgAspect = img....
10 votes
1 answer
5k views
DOM replace entire style attribute (CSSStyleDeclaration) on element
I know that to replace a single style, the code looks something like this: myDOMElement.style.height = '400px'; But what if I want to completely replace the entire style object in one fell swoop, ...
4 votes
3 answers
12k views
How to use Javascript to add multiple style properties to one element?
I've tried various renditions of this code to try and change a certain element for a coding exercise but non of them seems to be able to change multiple styling properties of an element on a button ...
5 votes
3 answers
2k views
Change CSS with properties defined in an object
Is it at all possible to dynamically style elements using CSS properties that are stored within a JS object? For example, changing both the width and background of a simple <div> element: <...
2 votes
1 answer
6k views
How to solve CSS2Properties doesn't have an indexed property setter for '0' error on Firefox?
I'm creating a div element throught Javascript and I want to copy the styles of the canvas initialized by a game engine that I'm using. I used Object.assign to achieve this and it works perfectly on ...
-1 votes
3 answers
2k views
Extract CSS from an element with javascript
Is it possible to build sort of an Applet that you can run into any page and by selecting a element you extract it's css attributes? Imagine like firebug allows you to select the div you want to see ...
2 votes
2 answers
447 views
Multiple inline styles with JS, how to set fallback?
So if I was to write this as a class in css I'd get something like: .cursorChange { cursor: move; /*IE*/ cursor: grabbing; /*Mozilla*/ cursor: -webkit-grabbing; /*Chrome*/ } However I ...