How to assign JavaScript value to a CSS property? [duplicate]


Tags: javascript,jquery,html,css

Problem :

I have a div element:

<div class="page">
        //some contents
</div>

CSS:

.page{
    bottom: 0;
    color: #1f1f21;
    font-size: 17px;
    font-weight: 400;
    left: 0;
    overflow: visible;
    position: absolute;
    right: 0;
    top: 0;
}

Getting screen height with JavaScript:

var page_height = screen.height;
alert(page_height);

How can I apply this page_height value to my .page class?

(i.e) I need to set screen height to my page class

For example, if screen.height = 405

I need to add height property

height: 405px;


Solution :

Use .height():

$('.page').height(page_height);

    CSS Howto..

    How to get partial scroll bar in html page?

    How do you name these tags in CSS? [closed]

    How to get CSS styling to shown on page? [closed]

    How can I get a label to right align in a table “cell” (td)?

    How to make .less files to have .css syntax highlight in Vim?

    CSS - How to set gradient color background for different heights

    How can I make my Div box holder look like this inside with CSS?

    How to properly use CSS in GWTP?

    How to make nav menu fall onto the page?

    HTML5 contenteditable div: show placeholder only if div has 1 child

    How to stop a timeOut animation that contains multiple timeOut animations within

    How to use weather API to create my weather HTML page [closed]

    How to remove dash inside text with CSS?

    how to set an element at fixed relative position in html rendering.? [closed]

    How to hide element that is currently mousedover and shown via :hover css pseudo class via jQuery

    Show on hover using CSS and HTML only

    How to wrap a DIV around a DIV with CSS

    How does this drop-down have the ^ shown?

    How are new lines made with text as background?

    How to modify divs in grid template site?

    How to make gridview in asp.net scrollable?

    web app CSS navbar retina icons - How can I fit a 60x60 icon into a 30x30 background-image on IE7+8?

    How to align elements so CSS fixed doesnt overlap on page load

    How is possible to get 2d transformation css vertical way

    How to detect when CSS value has changed?

    How to get rid of background when something is clicked

    how to display navigationMenu div left side of the slider

    Show window inside any web page

    How to call static block with styles.css

    Bootstrap, css How to change background