0

I want to run a function based on the eq() selector:

$('div.entry-content div.one_fifth').eq(0, function(){
    $(this).css({background: 'url(../wp-content/themes/genesis/images/plant_hire.jpg) no-repeat center'});
    $(this).on('hover',function(){
     alert('Test');
    });
});

What is wrong with my syntax since the inside function is not working

Thanks

5
  • 1
    .eq() has no callback. Commented May 14, 2013 at 18:20
  • 1
    the .eq() method does not and should not accept a second parameter. Commented May 14, 2013 at 18:20
  • yeah...but you get the idea of what I am trying to do...This is best as I can explain it... Commented May 14, 2013 at 18:21
  • Add your HTML as well. It could be your html. Commented May 14, 2013 at 18:23
  • No we don't get it, as it makes no sense to have a callback on a completely syncronous method that returns the new collection anyway, and can be just chained with the methods you're trying to use inside the "callback" ? Also, there is no on('hover') (well, there is, but you should'nt use it)! Commented May 14, 2013 at 18:29

1 Answer 1

3

This will select the zero index of your selector, change the css, and then attach the event handler for hover.

$('div.entry-content div.one_fifth')
    .eq(0)
    .css({background: 'url(../wp-content/themes/genesis/images/plant_hire.jpg) no-repeat center'})
    .on('hover',function(){
        alert('Test');
    });

EDIT, I cut and pasted what the OP originally had, I just assumed there were no syntax errors.

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

1 Comment

you have an extra });, otherwise looks fine.

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.