Trying to insert into DOM using JS

How would I add this:

body:after {
  content: "";
  position: absolute;

To this line:

.style.background = "url(image-01.png) no-repeat -9999px -9999px";

It would look something like this:

But this isn’t correct.

.style.background = "url(image-01.png) .style.content = "".style.position: "absolute" no-repeat -9999px -9999px";

Your question is confusing.

Take a look at this doc if you are trying to insert into DOM using JS.

I’m trying to add these properties:

body:after {
  content: "";
  position: absolute;

To this line:

.style.background = "url(image-01.png) no-repeat -9999px -9999px";

What’s confusing about that?

This isn’t written right:
What am I doing wrong, and how would I fix it?
https://jsfiddle.net/g6oaht8f/268/

document.getElementById("stuff in here").body.style.background = "url(https://i.imgur.com/fOfpsiC.png) content = "" position: "absolute" no-repeat -9999px -9999px";

body:after {
  content: "";
  position: absolute;
  left: -9999px;
  top: -9999px;
  background: url(https://i.imgur.com/fOfpsiC.png) no-repeat 0 0;
}

I was only able to get this far:

I need to add this to it:

body:after {
  content: "";
  position: absolute;
.body.style.background = "url(https://i.imgur.com/fOfpsiC.png) no-repeat -9999px -9999px";

Is this what you want?

const body = document.querySelector("body");

body.style.background = "url(https://i.imgur.com/fOfpsiC.png) no-repeat";

/* -9999px -9999px makes the image "disappear" not sure what you are trying to do with it? */
/* body.style.background = "url(https://i.imgur.com/fOfpsiC.png) no-repeat -9999px -9999px"; */

body.style.content = "";
body.style.position = "absolute";

https://jsfiddle.net/g6oaht8f/277/

Edit: If you want to set or modify a pseudo element, that is another story altogether.

Not really possible, as @lasjorg says — the way the guy in the linked article gets around it is insane. You are using JS, you can insert any real element into the DOM, you are not restricted as you are in CSS. Also, syntax for pseudo elements is :: not :

1 Like