-2

I am trying to do condition, that checks if my 8 classes are same border color, it executes something.

For example this:

var alt = $(".test").css;
var altt = $(".test").css("border", "5px solid green");

if (alt == altt) {alert()}

Just colors all borders green and doesnt pop up alert

I also tried a lot of different variants of this and it just usually makes syntax error or something else, but nothing works.. I also searched about this question but couldn't find anything that would help me.

I am very inexperienced with jQuery, but I really need to get this working.

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Einaras
  • 21
  • 4
  • 1
    first one returns a function not an actual css value .... those 2 variables will never match. Please explain in words what you are trying to do – charlietfl Sep 07 '15 at 18:59
  • I want it to check if all my class .test elements has same border, and if it does it does soemting, for example `alert()` – Einaras Sep 07 '15 at 19:14

1 Answers1

0

What you are looking for can be done using this code:

if( $('.test').css('border') == '1px solid rgb(0, 128, 0)' ) alert(1);

Note that .css() always returns colors as RGB values. If you need to use HEX values, consider conversions. You can find some samples here: RGB to Hex and Hex to RGB

Community
  • 1
  • 1
Alex Goncharenko
  • 1,036
  • 2
  • 12
  • 22