Search code examples
bookmarklet

Set body to backwards with JS bookmarklet


Is there a way to change the body of a website to backwards? I tried javascript:document.body.innerHTML = '<bdo dir="rtl" >' + document.body.innerHTML + '</bdo>;


Solution

  • You have to specify the tags explicitly. For example:

    javascript:(function() {
        var txtEls = window.document.body.querySelectorAll("p, a, td");
        for (i = 0; i < txtEls.length; i++) {
            txtEls[i].innerHTML = '<bdo dir="rtl">' + txtEls[i].innerHTML + '</bdo>';
        }
    })();
    

    Try to run the bookmarklet on this page.