iMarkDesigns iMarkDesigns - 4 months ago 7
CSS Question

how to get the value of css style using jquery

I'd like to know what type of method should I use to get the value of CSS style. I want to set it to jQuery so that I can create conditions to match on CSS "left" value.

Here is the CSS and HTML tag with the style attributes.

<div class="items" style="left: -900px"> <span>some content here</span> </div>

Here is my jQuery code to get the value.

var n = $("items").css("left");
if(n == -900){
$(".items span").fadeOut("slow");

I'd like to know if this method is correct because it is not working in my end. Thanks in advance for the little help.

Note: left value was dynamic, and it was changing to these value: -900px, -1800px, -2700px, -3600px, -4500px...


I doubt css understands left by itself. You need to use it specifying position. You are using .css() correctly

position: relative/absolute/whatever;
left: 900px;

heres a fiddle of it working

and without the position here's what you get

Change your if statement to be like this - with quotes around -900px

var n = $("items").css("left");
  if(n == '-900px'){
  $(".items span").fadeOut("slow");