Reputation: 21
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;
}
Upvotes: 0
Views: 390
Reputation: 13110
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>
Upvotes: 1