I have a div (the styles are made by another js script). I want to get the values of --rows
and --columns
into another JS file. When I output them to the console it just outputs "". What is wrong?
const rowscolumns = document.getElementById('sliderh')
var rows = rowscolumns.style.getPropertyValue("--rows")
var columns = rowscolumns.style.getPropertyValue("--columns")
console.log(rows)
<div id="sliderh" class="slider_box" style="--relative_pos:46.5px; --rows:7; --columns:5;">
...
</div>
Ok here is the other js script that ads the style elements:
function relcalch() {
let relPos2 = (valueh * Stepsh) / hWidth * 100
elementh.style.setProperty("--relative_pos",`${relPos2}%`)
elementh.style.setProperty("--rows",`${valueh + 3}`)
elementh.style.setProperty("--columns",`${valuew + 3}`)
texth.innerHTML = valueh +3
}
2
Answers
I have figured out that I was doing a really stupid thing in the first place: My code now is using data, not style (for rows and columns):
First the html:
Now setting the data:
And then retrieving said data in another js file (it outputs when a button is pressed):
if you check the documentation here as it says:
It shows your property as String in quotes "". Nothing is wrong.