How to get class style if I have nothing but class name?

This is the css code:

# skin.css
.my_class {
  attr1: value1;
  attr2: value2;
}

I want to get these properties, but it $(".my_class")does not work, because I do not have an element with a class my_classin mine DOM. Is there any way to achieve this?

+3
source share
2 answers

You can create a hidden DOM element and add it to the body, and then delete:

$('<div class="my_class" style="display: none;"></div>').appendTo("body").css("attr1"); // => value1

You will need to do something differently if you care about the property display, for example. use opacityeither visibilityor position: absolute; top: -100000px;.

0
source

- DOM, , , css. , display , , , .

$('<div class="my_class" style="display:none"></div>').appendTo('body').css("attr1");

( ): http://www.jsfiddle.net/uTcPD/1/

0

Source: https://habr.com/ru/post/1776762/


All Articles