how to pass javascript variable to css

419
April 06, 2017, at 9:27 PM

I am using scrollbar function in my div tag.

i want to set the scroll bar to my browser height.

i am trying to get the value like this.

javascript

<script>
var height = window.innerHeight;
</script>

css code

    <style>
      .kryesore {
               overflow-y: scroll;
               overflow-y:auto;
               height:height-320px ;
            }
    </style>

but it is not working can any tell me the correct solution.

Answer 1

You can't reference JS variables through CSS, but you can change CSS with JS.

Try:

JS

document.querySelector('.kryesore').style.height = height;
Answer 2

You can't pass variables but you can set in javascript by using class name Help Here!

//using pure Javascript
document.getElementsByClassName("kryesore").style.height = window.innerHeight;
//using JQuery
$('.kryesore').css("height",window.innerHeight); 
Rent Charter Buses Company
READ ALSO
CSS inheriting div width

CSS inheriting div width

I have essentially the following code:

346
php include file also include the style of this file

php include file also include the style of this file

i have a PHP codes in indexphp like this:

344
How to change stacking order of bg image?

How to change stacking order of bg image?

How can I make it so that the mouth, eyes, and eyebrows appear on top of the face without changing the html? (The mouth is in the wrong position so I can see it)

314