css: how to access a value that is not used by an element?

Tags: javascript,css

Problem :

I have a DIV that gets its height from a CSS class in a separate stylesheet. But that height is sometimes changed in Javascript. Can I read the CSS height direct from the stylesheet without creating a new element?

Solution :

You can do something like this:

 var myDiv = $("#myId"); 
 alert('initial height from css is: ' + myDiv.css("height"));

 alert('height modified by js is: ' + myDiv.css("height"));

 // store modified height value
 var height = myDiv.css("height");

 // set height to an invalid value

 alert('height is now retrieved from css again: ' + myDiv.css("height"));

 // restore height value

I created an example on jsfiddle.net, you can view it here.

    CSS Howto..

    How to make this CSS hamburger menu entirely clickable?

    How to leave input file button usefull for drag and drop from desktop, but avoiding local redirection

    How to place scroll bar on side of table?

    How to keep sub div from considering height of its cousin?

    How to select every 4th div inside another div CSS Selector [closed]

    How to make a wavy border line to separate background images in html5/css?

    how to set width of a div in percentage minus certain pixels using javascript or css

    How to make possible vertical scroll on popup and disable vertical scroll for page by using CSS?

    How to style an iframe?

    How to use YUI Compressor in Ant build script for javascript and css

    How to avoid name collisions of css class names

    How can I align my paragraphs in CSS/bootstrap properly?

    How can I make DIVs within a display: table-cell fill the cell?

    Image, src, href in same span. How to locate? Webdriver, css locator

    How can I vertically center this css/javascript based modal dialog?

    How do I get a fixed positioned footer, fixed width right column, left column for the rest using CSS lay-out?

    How can I make the left div expand and the right div have constant width?

    How to expand textarea to fit text vertically and horizontally?

    How to merge .CSS files with Sass (or other tool)? [duplicate]

    How do you set a JavaScript onclick event to a class with css

    How to add a custom css selector to just a span??

    How with JQuery cause Hover on diffrent element than mouse is currently on top of

    How to center content vertically with unknown content and fixed layout

    Navbar on left of page, how to let content resize to match screen size?

    How to change elevation property of paper-card?

    How to use image tag in body of html instead of loading image from css?

    How do I change phpmyadmin font size for sql query box?

    How to read from CSS files with jQuery

    Materialize CSS Showing errors on form fields

    how to make div fixed and ot move upon window resize