What is the vanilla JS equivalent of jQuery's $(document)?

  • A+

I'm trying to figure out the vanilla equivalent of the following code:

$(document).attr('key', 'value); 

So far I've looked into

  • document - it's not an element so you cannot call setAttribute on it
  • document.documentElement - returns the html tag. This is not the same "element" that jquery is targeting
  • $(document)[0] seems to return a shadow element in Chrome Inspector
  • $(document).attr('key', 'somethingUnique') doesn't exist in the Chrome Inspector

Is jQuery creating it's own shadow element mock of the document so it can treat it like a real element? What element is jQuery actually referencing when you do $(document)?


jQuery is just assigning the value to document directly.

$(document).attr('test', 'hello world'); console.log(document['test']); // prints "hello world" 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: