0

I'm trying to change the background color of all the divs which have a distance of 100px or more relative to their parent's top.

I'm using:

$('.box').filter(function () {
    return $(this).position.top > 99;
}).css('background', 'red');

Which doesn't seem to work.

You can check it out here: http://jsfiddle.net/68LQD/4/

2
  • position is a method, not a property Commented Jan 29, 2014 at 17:56
  • could you use a $.each() on the .box class? Where a simple if statement should do... Commented Jan 29, 2014 at 17:57

2 Answers 2

1

You need to invoke the function position. You left off the ().

position().top > 99;

Complete code:

$('.box').filter(function () {
    return $(this).position().top > 99;
}).css('background', 'red');

Live demo (click).

Sign up to request clarification or add additional context in comments.

Comments

1

Here is the working fiddle : Working Fiddle

Try

$(this).positon().top for relative to parent

$(this).offset().top for relative to document : Fiddle

1 Comment

offset is relative to document, not parent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.