Can't change z-index with JQuery

后端 未结 5 1404
别跟我提以往
别跟我提以往 2020-12-10 10:29

I, for some reason, can\'t change the zIndex of an element using jQuery. I\'ve searched all of this website and Google but couldn\'t find the right answer. I am trying to

相关标签:
5条回答
  • 2020-12-10 10:46

    That's invalid Javascript syntax; a property name cannot have a -.

    Use either zIndex or "z-index".

    0 讨论(0)
  • 2020-12-10 10:46

    zIndex is part of javaScript notation.(camelCase)
    but jQuery.css uses same as CSS syntax.
    so it is z-index.

    you forgot .css("attr","value"). use ' or " in both, attr and val. so, .css("z-index","3000");

    0 讨论(0)
  • 2020-12-10 11:04

    Setting the style.zIndex property has no effect on non-positioned elements, that is, the element must be either absolutely positioned, relatively positioned, or fixed.

    So I would try:

    $(this).parent().css('position', 'relative');
    $(this).parent().css('z-index', 3000);
    
    0 讨论(0)
  • 2020-12-10 11:04
    $(this).parent().css('z-index',3000);
    
    0 讨论(0)
  • 2020-12-10 11:08

    because your jQuery code is wrong. Correctly would be:

    var theParent = $(this).parent().get(0); 
    $(theParent).css('z-index', 3000);
    
    0 讨论(0)
提交回复
热议问题