2

I have conflict between some add-ons on my site. Using Firebug, I noticed that if I add "!important" to the z-index I can avoid the conflict.

but the z-index value is set using JavaScript and not CSS

so how do I add "!important" to the following JS code:

this.menu = $("<ul>")
   .addClass("ui-autocomplete")
   .appendTo(this.document.find(this.options.appendTo || "body")[0])
   .zIndex(this.element.zIndex() + 1)  // !! <- here // !!
   .hide()
   .data("menu");

EDIT: from the proposed answer [How to apply !important using .css()? ] I understand that I need to add the following code -

if (XXX.style.setProperty) {  // IE 9- does not support...
    XXX.style.setProperty ("z-index", (this???.element.zIndex() + 1), "important");
  }

How do I add it: what is XXX in my case? and "this" ?

Edit 2: Since it became jQuery syntax question, I asked it with different tags in - How to add 'if' to jQuery chain code

Community
  • 1
  • 1
Atara
  • 3,523
  • 6
  • 37
  • 56
  • 1
    possible duplicate of [How to apply !important using .css()?](http://stackoverflow.com/questions/2655925/how-to-apply-important-using-css) – Saad May 31 '15 at 09:40
  • The zIndex value is calculated from parent element : .zIndex(this.element.zIndex() + 1) so I cannot use CSS rule – Atara May 31 '15 at 09:47

4 Answers4

3

I received the answer in another thread - How to add 'if' to jQuery chain code

use -

.each(function() {
    this.style.cssText+= 'z-index: '+(parseInt($(this).css('z-index'))+1)+' !important';
  })

but after struggling with the code in several functions, I preferred to add a class and a rule to this class -

this.menu = $("<ul>")
  .addClass("ui-autocomplete")
  .addClass("ui-autocomplete-hover-header")  // !! added!
. . .

.ui-autocomplete.ui-autocomplete-hover-header {  
  z-index: 5004 !important; }
Community
  • 1
  • 1
Atara
  • 3,523
  • 6
  • 37
  • 56
1

I think i got this

this.menu = $("<ul>")
   .addClass("ui-autocomplete")
   .appendTo(this.document.find(this.options.appendTo || "body")[0])
//   .zIndex(this.element.zIndex() + 1)  // !! <- here // !!
   .style.setProperty ("zIndex", zIndex()+1, "important");
   .hide()
   .data("menu");
lakshya_arora
  • 791
  • 5
  • 18
0

Why not using css to this? For example

this.menu = $('<ul class="high-zindex">')....

and then define .high-zindex { z-index: 9999 !important }

-2

Try this out.

.zIndex(this.element.zIndex() + 1 + '!important')