4

Why can't I change the CSS of this element?

  $("div.example ul li").mouseover(function () {
      var ul_teirs = $("div.example ul li").find('ul');
      var second_teir = ul_teirs[0];
      var third_teir = ul_teirs[1];

      second_teir.css({
         ...
      });
  });

error I'm getting:

Uncaught TypeError: Object #<HTMLUListElement> has no method 'css'

2 Answers 2

15

When you use [] to access an item in a jQuery array, you get the DOM element, not a jQuery object, so it doesn't have any jQuery methods.

Try .eq() instead:

var second_tier = ul_tiers.eq(0);
second_tier.css({ ... });

(Note that I changed the spelling of "tier" in the variable name. Sorry, I can't help myself.)

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

1 Comment

Whoops, noticed that I was incorrect here - @Dogbert had the right answer. Since this was already selected as correct, I'm updating my answer to fix it.
3

Try

  var second_teir = ul_teirs.eq(0);
  var third_teir = ul_teirs.eq(1);

Comments

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.