0

I managed to insert an attribute in the html tag, using this code in JavaScript:

document.documentElement.style.cssText = 'cursor: url("https://image0.png"), auto !important;';

Therefore, the result in CSS was:

html {
    cursor: url("https://image0.png"), auto !important;
}

Now, I know this is probably a silly question, but I can't find the right JavaScript code to obtain this CSS result:

a {
    cursor: url("https://image1.png"), auto !important;
}

.content img {
    cursor: url("https://image2.png"), auto !important;
}
2
  • 1
    stackoverflow.com/a/23157406/1169519 Commented May 20, 2021 at 12:29
  • Why are you using JavaScript to add these styles? You can just have the styles in a CSS file and link to that. Commented May 20, 2021 at 12:34

1 Answer 1

1

As I read your question you would like to dynamically add CSS styles to your document using JavaScript.

You can add one or more style elements to the document.body. In this example it is just a string of CSS. An alternative could be to add a link element to the document.head.

var styleELm = document.createElement('style');
styleELm.innerText = "p {color: Steelblue} a {text-decoration: none}";
document.body.appendChild(styleELm);
<p>Hello <a href="#">World</a></p>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.