0

When using normal CSS stylesheet I just use such code:

display:inline;
display:block\9;

and it works instantly.

But when I got the same code inside JavaScript it just doesn't work making whole input field invisible. How the \9 hack for IE8 should be entered ?

inp.style.display="inline";
inp.style.display="block\9";
  • 1
    what is `\9` supposed to do and when would you use it? – charlietfl Mar 03 '15 at 17:01
  • 1
    ^^ agreed. I've never heard of/apparently needed this. – jbutler483 Mar 03 '15 at 17:02
  • @charlietfl: Apparently it makes IE9 read it [according to this](http://stackoverflow.com/a/8004962/3436942) - but still can't think of a use case – jbutler483 Mar 03 '15 at 17:04
  • 1
    Can't imagine a use case for elements needing to be block in IE but inline in other browsers. Even if it was needed, only way I could see doing this with script is in a style tag – charlietfl Mar 03 '15 at 17:08

3 Answers3

1

You need to escape the backslash because it's a special character in strings:

inp.style.display = 'block\\9';
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I'm not familiar with the `\9 hack`. Maybe it only works when it's reading the CSS file, not in style attributes. – Barmar Mar 03 '15 at 16:55
0

My guess is that JS is interpreting the "\9" as a literal "9" and you are really ending up with inp.style.display="block9";.

To fix this, use a double backslash:

inp.style.display="block\\9";

Not tested, but it's something to try.

mjswensen
  • 3,024
  • 4
  • 28
  • 26
  • I am trying it in Chrome and apparently it's detecting that `block\9` is not a valid value for `display` and not applying it to the element. Sorry. – mjswensen Mar 03 '15 at 16:58
0

Some context about the \9 CSS hack.

I'd advise you against using hacks for IE9 as this is the last version of IE considering conditional comments.
Conditional classes are a better practice imho, more robust or future-proof.

Otherwise Browserhacks is a great resource when you've to use one those dreaded hacks. Filter for IE 9 and you'll have hacks using JS properties for IE6-10 or 8-10 or 9 only, etc.
The CSS hacks proved reliable when I had to use them (sigh), I didn't test the JS ones.

Community
  • 1
  • 1
FelipeAls
  • 21,711
  • 8
  • 54
  • 74