1

I need to replace the 4th line in -

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

with 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 merge this code?
  • what is 'XXX' in my case?
  • what is "this" ?

[relates to How to add 'important' to zIndex ]

Community
  • 1
  • 1
Atara
  • 3,523
  • 6
  • 37
  • 56
  • FYI, `z-index` is supported from IE6, albeit with a few issues – adeneo May 31 '15 at 11:29
  • 1
    You can just set the property with `.css()`. Browsers that don't support it will just ignore it. – JJJ May 31 '15 at 11:30
  • I'd be more concerned with the totally invalid syntax, like there is `zIndex` function, and that you're calling `find` and `appendTo` on native DOM nodes etc. – adeneo May 31 '15 at 11:31
  • setProperty() is not supported by elder browsers – Atara May 31 '15 at 11:48
  • .css() cannot add the needed 'important' priority – Atara May 31 '15 at 11:48
  • find() and appendTo() are from the original add-on. I just want to set zIndex with 'important' priority. I am not going to review all code – Atara May 31 '15 at 11:50

1 Answers1

1

This should do it:

this.menu = $("<ul>")
  .addClass("ui-autocomplete")
  .appendTo(this.document.find(this.options.appendTo || "body")[0])
  .each(function() {
    this.style.cssText+= 'z-index: '+(parseInt($(this).css('z-index'))+1)+' !important';
  })
  .hide()
  .data("menu");
Rick Hitchcock
  • 35,202
  • 5
  • 48
  • 79
  • Thanks. Is [this.element] is equal to [$(this)] ? the new zIndex should be one higher than [this.element] – Atara May 31 '15 at 14:02
  • `this` by itself is the DOM element, which you can apply DOM methods and properties to such as `style`. `$(this)` lets you call jQuery methods on the DOM element, but it does *not* allow you to access DOM methods and properties. – Rick Hitchcock May 31 '15 at 14:06
  • so, in the original code [ .zIndex(this.element.zIndex() + 1) ] it says increment [b]my-self[b] zIndex. not related to its [b]parent[b] zIndex? – Atara May 31 '15 at 14:13
  • Correct. `this` within the `each()` method refers to the newly-created `ul` element. – Rick Hitchcock May 31 '15 at 14:16
  • If you could post a fiddle or link with all your code, I could confirm if this works. – Rick Hitchcock May 31 '15 at 14:17
  • Thanks. solved. Actually it solved the original question about css and important. about adding 'if' to chain code the answer is - add the 'if' inside '.each(function() {' . . . – Atara Jun 01 '15 at 09:28