Home  >  Q&A  >  body text

html5 - Can HTML or JS dynamically change .css attributes?

For example, is it possible to change the attribute value of *.css or <style> based on the input value content?
For example: use the input:color tag to get the selected color value and update the color of the scroll bar? (This must use a selector, not inline)


One method that comes to mind right now is to use js to create a <style> on the current page, and then modify the content in this tag. Wondering if you have any other ideas?


It feels like I didn’t describe it clearly. The attribute value of the css style sheet needs to be given according to the value. For example: if the user selects #6ec42a, then the scroll bar becomes the color #6ec42a. In this case, it is not easy to prepare CSS files in advance. Can't we exhaust all hexadecimal colors and make different CSS files? But I am very grateful for the method you just shared. I don’t know this either, so I just learned it!

伊谢尔伦伊谢尔伦2684 days ago900

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-24 11:38:09

    Write several .css files with different plans, and use js to dynamically load the css files according to the situation

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-24 11:38:09

    For example, is it possible to change the attribute value of *.css or <style> based on the input value content?
    You can replace *.css with attribute selector
    For example: $("[href*=aaa.css]").attr({href: 'bbb.css'});

    reply
    0
  • Cancelreply