开发者

How can I update an existing <style> from JavaScript?

开发者 https://www.devze.com 2023-01-24 03:09 出处:网络
I need to alter a <style> from the client-side - something like this: <head> <style> img.Bordered

I need to alter a <style> from the client-side - something like this:

<head>
    <style>
        img.Bordered
        {   border-style: dashed;
        }
    </style>
    <script type开发者_C百科="text/javascript">
        function OnBorderChanged () {
            //Set "border-style" to "solid" for Bordered images.
        }
    </script>
</head>

What is the process for this?


See: http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript and http://www.quirksmode.org/dom/changess.html

These articles explain how to dynamically add and remove entire styles.

Note that the first article give you a pretty good cross-browser set of functions to use. The quirksmode article basically explains how it all works.


using jquery's css method:

http://api.jquery.com/css/

e.g:

$("img.Bordered").css('border-style', 'solid');
0

精彩评论

暂无评论...
验证码 换一张
取 消