<html> <head> <script> function boom() { document.getElementById("div").setAttribute("dir", "rtl"); } </script> <body onload="boom()"> <div id="div" style="width: 0;"> Foo a bar baz</div> </body> </html>