Why are obtained incorrect css values, if load css via script?
Hello everyone! I am creating a website. I need to measure the width of the element. If I connect through the
link
, then everything works fine. If I connect via a script, it returns an incorrect value. Everything is good in ie, Google chrome returns 1333, on
this
example. In the example, the measured element
el1 (elipse)
. Code:
- function load_style() {
- var window_width = $(window).width();
- var window_height = $(window).height();
- if (window_width > window_height) {
- $("head").append($("<link rel='stylesheet' type='text/css' href='styles/style.css'>"));
- } else {
- $("head").append($("<link rel='stylesheet' type='text/css' href='styles/style_mobile.css'>"));
- }
- var text_page_1_width = $("#main").find(".page_1").find(".el1").width();
- alert(text_page_1_width);
- }
- $(document).ready(function () {
- load_style();
- });