I have some trivial JavaScript to effect a style change:
sel = document.getElementById('my_id');
sel.className = sel.className.replace(/item-[1-9]-selected/,'item-1-selected');
return false;
This works fine with the latest versions of FF, Opera and IE, but fails on the latest versions of Chrome and Safari.
It affects two descendants, which happen to be siblings. The first sibling updates, but the second doesn’t. A child of the second element also has focus and contains the <a> tag that contains the above code in an onclick attribute.
In the Chrome “Developer Tools” window if I nudge (e.g. uncheck & check) any attribute of any element, the second sibling updates to the correct style.
Is there a workaround to easily and programmatically “nudge” WebKit into doing the right thing?
above suggestions didnt work for me. but the below one does.
Want to change the text inside the anchor dynamically. The word "Search". Created an inner tag "font" with an id attribute. Managed the contents using javascript (below)
script contents:
Not that this question needs another answer, but I found simply changing the color by a single bit forced a repaint in my particular situation.
The
setTimeout
proved critical to move the second style change outside the current event loop.I would recommend a less hackish and more formal way to force a reflow: use forceDOMReflowJS. In your case, your code would look as follows.
I came up here because I needed to redraw scrollbars in Chrome after changing its css.
If someone's having the same problem, I solved it by calling this function:
This method is not the best solution, but it may work with everything, hiding and showing the element that needs to be redraw may solve every problem.
Here is the fiddle where I used it: http://jsfiddle.net/promatik/wZwJz/18/
The only solution works for me is similar to sowasred2012's answer:
I have a lot of problem blocks on page, so I change
display
property of root element. And I usedisplay: table;
instead ofdisplay: none;
, becausenone
will reset scrolling offset.I tried morewry answer but it does not work for me. I had trouble to have the same clientWidth with safari comparing to others browsers and this code solved the problem:
It is really strange because if I try again to get the clientWidth after get_safe_value, I obtain a bad value with safari, the getter has to be between
sty.transform = "translateZ(1px)";
andsty.transform = "";
The other solution that works definitively is
The problem is that you lose focus and scroll states.