How Do I make Changes in .CSS File Using Jquery Or Javascript?

前端 未结 7 780
既然无缘
既然无缘 2021-01-22 12:27

I would like to know that is there anyway to make changes in .css file using Jquery or javascript. I know, I can dynamically add css properties(or classes) to DOM Element but I

相关标签:
7条回答
  • 2021-01-22 12:50

    Not really.

    There's some ActiveX stuff in IE that lets you modify things in the file system but aside from not being a recomended solution, they'd only work in IE anyway.

    You can still modify the styles your page uses for selectors in your css files, but you won't actually be modifying the css file itself.

    0 讨论(0)
  • You can rather have different css files written based on your requirement then change css file using click event which will eventually change the look of ur webpage or a part of your webpage. Here is the solution. http://www.jquery4u.com/dynamic-css-2/jquery-change-css-file-2/

    0 讨论(0)
  • 2021-01-22 12:57

    I Don't think there is any easy way for what are you looking for..!!

    0 讨论(0)
  • 2021-01-22 12:59

    You cannot do it directly within jQuery, but you can load the .css file with jQuery, edit the contents and then send the data to a php or asp.net page which overrides the .css file with the new contents. But this is very dangerous because people can exploit the code and save any data in that .css file unless you have some security procedure but I can't think of any way you can make that work safely.

    0 讨论(0)
  • 2021-01-22 12:59

    You could generate the CSS server-side and display inline (in the head). That would allow you to serve up styles on a per-user basis.

    0 讨论(0)
  • 2021-01-22 13:01

    You can't physically change the contents of a file using Javascript in a browser. That's for security reasons, so that content on a web page can't manipulate content on your computer (apart from cookies).

    0 讨论(0)
提交回复
热议问题