I
I
intriga932020-12-21 21:45:56
JavaScript
intriga93, 2020-12-21 21:45:56

How to add g styles?

not inline
, but through js , that is,
initially we
var g = document.createElement('g');
get
<g transform="rotate(-12, 55, 35)"></g>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Kornilov, 2020-12-21
@intriga93

g.setAttribute('transform', "rotate(-12, 55, 35)")
?

A
Alexander, 2020-12-21
@Aleksandr-JS-Developer

Please clarify your question.
If you add styles via JavaScript, then be prepared for the fact that the styles will be added to the element exactly inline, but programmatically.

var g = document.createElement('g');
g.style = 'color: red; margin: 8px;';

If you need to add styles without inline, but through JS, then you need to write the appropriate styles in CSS and include them through adding classes to the HTML element.
var g = document.createElement('g');
g.classList.add( 'your-css-class' );

docks:
Styles and Classes (ru)
Attributes and Properties (ru)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question