i've tried these examples separately. For some reason, I can modify other values from x.style such as width and height, and even add position, top, and left attributes/values. For the max attributes, I get nothing, at least not through tampermonkey. The code works just find in the console

(function() {
    'use strict';

    var x;
    x = document.getElementById("img");
    x.style.maxHeight = "100vh";
    x.style.maxWidth = "100vw";
    x.style.width = "";
    x.style.height = "";
    x.style.position = "fixed";
    x.style.top = "0";
    x.style.left = "15%";
})();
    x.setAttribute("style", "max-height: 100vh; max-width: 100vw; position: fixed; top: 0px; left: 15%;");

both work fully inside the console but not in the script, and I'm not sure why

getElementById("img")

I've seen some browser issues with this particular method just recently. id is supposed to be unique to one element/tag albeit some sites still don't pay attention to this, use it incorrectly and optionally abusively... then .user.js doesn't seem to handle them in the scope they are assigned.

  1. Try another browser and .user.js engine e.g. not TM and see if you can replicate the issue.
  2. Try getElementsByTagName and see if that works better for you. You may need to use a selector with querySelectorAll if this alternative is "too wide" of a capture in the DOM.
  3. Something else?

P.S. As OUJS Admin I fixed your lack of code fences on your snippets... please see this FAQ on how to use them.

Thank you for the response. It seems to be an issue with chrome then. I've had success using it with firefox. Thank you. The reason I've been confused is that there's only one img id and every value tested was able to be changed, removed, etc., except for the max values.

My two cents:

I think using x.style.cssText = "max-height: 100vh; max-width: 100vw;/* and so on */"; is more solid than x.style.property = 'something';

Also, do not set width and height as empty string, rather set them to auto or initial.

Thanks for recommendations, though that snippet doesn't seem to work with my code after translating to that format