0

.css

.Fchkbox, .Fchkbox-lg {
   position: absolute;
   display: block;
   margin-top: 10px;
}

Here I am getting style attribute value if

1>getStyleRuleValue("margin-top",".Fchkbox");
  result:-10px;

2>getStyleRuleValue("margin-top", ".Fchkbox-lg");

So here I am not getting the result as 10px....why? How can I resolve this?

Roy Scheffers
  • 3,832
  • 11
  • 31
  • 36
  • 3
    Please, consider rewriting your question, which is unreadable at the moment. – Orabîg Oct 24 '16 at 09:34
  • getStyleRuleValue("margin-top", ".Fchkbox-lg" document.styleSheets[2]); – Mahi Oct 24 '16 at 09:43
  • What does getStyleRuleValue do. We have no insight of this method... – AlbertVanHalen Oct 24 '16 at 09:47
  • @AlbertVanHalen for you read rlemon answer http://stackoverflow.com/questions/16965515/how-to-get-a-style-attribute-from-a-css-class-by-javascript-jquery – Mahi Oct 24 '16 at 09:53
  • sorry sir .!this is my first time......,i stuck while writing the question in correct format. – Omprakash Kale Oct 24 '16 at 09:57
  • You should split the stylerule on comma including whitespace. `rule.selectorText.split(/\,\s?/)` The two selectors in your stylerule are put into an array and checked against the second argument of the method call. ' .Fchkbox-lg' is put into the array (note the leading space!) which is not the same as '.Fchkbox-lg'; therefore returning null. – AlbertVanHalen Oct 24 '16 at 09:57

1 Answers1

0

Regarding the method described in this article : How to get a style attribute from a CSS class by javascript/jQuery? the code should be tweaked. The stylerule is split on a comma into an array of different selectors. You should split on comma including whitespace. rule.selectorText.split(/,\s?/)

Community
  • 1
  • 1
AlbertVanHalen
  • 632
  • 4
  • 12