0
`   input.star:checked ~ label.star:before {
            content: '\f005';
            color: #FD4;
            transition: all .25s;
        }    `

how can I apply this code by javascript ?

2
  • do you consider in using jquery? Commented Sep 27, 2017 at 5:48
  • jquery won't make this any simpler than plain javascript Commented Sep 27, 2017 at 6:08

1 Answer 1

2

If you want add a style with js, you can use the insertRule() of style.sheet, the example code:

var sheet = (function() {
	// Create the <style> tag
	var style = document.createElement("style");

	// WebKit hack :(
	style.appendChild(document.createTextNode(""));

	// Add the <style> element to the page
	document.head.appendChild(style);

	return style.sheet;
})();

// for a test
sheet.insertRule("body { background-color:red;}", sheet.length);

// for your code just replace param
// sheet.insertRule("input.star:checked ~ label.star:before {content: '\f005';color: #FD4;transition: all .25s;}}", sheet.length);

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.