JavaScript: Get CSS properties of an element before inserting it into the page
Here’s a fun one: You’ve got something like an icon image, and you want to insert it into your web page using JavaScript.
Easy, right? Well, maybe not…
What if you need to know the size of the <IMG> before you plop it in the DOM tree, but you also have @media queries in CSS that change the width on the fly, for example?
Maybe your CSS shrinks or expands the image based on device orientation, screen size, etc.
Can it be done? Why yes, it can!
Recent Comments