www.webdeveloper.com
Results 1 to 3 of 3

Thread: updating 'content' of css style from a java script function?

  1. #1
    Join Date
    Nov 2005
    Location
    shores of Lake Ontario, Canada
    Posts
    57

    updating 'content' of css style from a java script function?

    I want to have a java script function to change the 'width' to 100px, as in the example below. I already know how to do it by calling a separate style class:

    document.getElementById('dynamicPicture').className="size1";

    but would like to add some "mathematics" to dynamically set 'width'.
    What is the syntax?
    Thank you.

    img.size0 {
    width:50px;
    }

    Thanks.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    1. In IE and Opera (partially I believe), you can use dynamic properties - not supported in Moz. browsers

    2. DOM access to style sheets. Unfortunately you can only access the index of the rule and not the class selector name.

    3. Find the relevant elements by searching the DOM tree:
    Code:
    var aIMG=document.getElementsByTagName('img');
    for(var i=0; i<aIMG; i++) {
        if(aIMG[i].className=='size0') {
            aIMG[i].style.width=aValue+'px';
            }
        }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2005
    Location
    shores of Lake Ontario, Canada
    Posts
    57
    Thanks.
    I was also recommended:
    document.getElementById('dynamicPicture').style.width=w+'px'
    (which is similar to your sugestion), and it works fine in my case.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles