AppleScript / Javascript : remove columns in Safari
.removeAttribute(attrName) takes an attribute name, not value.
The attribute name is 'class', the value is 'sortable cardTypeDisplayName'.
However, that's not going to fix the problem either. Removing the attribute from the element doesn't remove the element entirely, it just removes the attribute, such that your example becomes &lt;td&gt;Visa&lt;/td&gt; — i.e. the column still exists.


To remove all elements with a class attribute exactly matching 'sortable cardTypeDisplayName', you can use the following JavaScript.

document.querySelectorAll("[class=\"sortable cardTypeDisplayName\"]")
        .forEach(el =&gt; el.remove());


This problem is with your JavaScript, not AppleScript. Debug your JavaScript in the web browser developer tools first before moving to AppleScript.

To run this JavaScript with AppleScript, keep in mind the quotes that need escaping. Look at the syntax highlighting to see how the quotes in the JavaScript are being parsed as quotes for AppleScript to use on the string itself, rather than given to JavaScript. These quotes need escaping.

tell application "Safari" to ¬
  do JavaScript "document.querySelectorAll(\"[class=\\\"module question-stats\\\"]\").forEach(el =&gt; el.remove());" ¬
    in current tab of window 1




tell application "Safari" to ¬
  do JavaScript "document.querySelectorAll('[class=\"module question-stats\"]').forEach(el =&gt; el.remove());" ¬
    in current tab of window 1