If you're styling an <input> element with Javascript, it appears that any properties you set this way get ignored in a :focus rule.
I've an example which illustrates this:
- Initially the background and border of the input element is set the same as the surrounding element (div.header)
- Clicking on the [open] link opens up the div.body element, which was initially not shown.
- I want to make it clear that the title is a text field, so change the background and border of the input to match the textarea that was just revealed.
I have a :focus rule for both the textarea and the input, to color the background yellow so it's obvious that the text field has focus.
But this doesn't work on the input element, seemingly because I've programmatically set those properties. If I don't set them, then the :focus works as expected. If the :focus rule sets properties that aren't also set in .css()
, then they're honored.
This is true on Safari, Firefox, Chrome and IE, so clearly is "expected behaviour", but I can't find anything online that says (why) this is correct.
Obviously I can implement what I want using blur and focus handlers, but I'm trying to understand why this is the way it is.