javascript - jquery - Object ... has no method 'css' - Stack Overflow

Why can't I change the CSS of this element?$("div.example ul li").mouseover(function ()

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'

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'
Share Improve this question edited Sep 24, 2011 at 5:00 Yi Jiang 50.1k16 gold badges138 silver badges136 bronze badges asked Sep 24, 2011 at 4:58 dgamma3dgamma3 2,3714 gold badges27 silver badges48 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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.)

Try

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1739468072a4128655.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信