www.webdeveloper.com
Results 1 to 3 of 3

Thread: using javascript to change css cursor

  1. #1
    Join Date
    Jul 2010
    Posts
    28

    using javascript to change css cursor

    Hi,
    I am trying to alter some css using external javascript. I have 48 thumbnails on a page which bring up a pointer cursor onmouseover. The thumbnails have div ids of 'thumb_2_2' up to 'thumb_2_49' and a css class of 'thumb2'. I need to alter the cursor so that in certain situations the pointer doesn't show.
    This is the css :
    Code:
    div.thumb2 {cursor:pointer;}
    I have tried altering the css class like this :

    Code:
    window.thumb2.style.cursor="default";
    and have also tried altering the individual divs like this :
    Code:
    for(var i=2; i<=49;i++){
    document.getElementById['thumb_2_'+i].style.cursor="default";
    }
    and also like this :
    Code:
    for(var i=2; i<=49; i++){
    document.images['thumb_2_'+i].style.cursor="default";
    }
    but nothing seems to work.

    I would be really grateful if anyone could help. Thanks.

  2. #2
    Join Date
    Sep 2007
    Posts
    317
    This code is working in Firefox 4.0b9.

    As far as I know:
    Code:
      
    <html>
    <head>
    <style type="text/css">
    div#pano1 { width: 100px; height: 161px; background-color: turquoise;  }
    div#pano2 { width: 100px; height: 161px; background-color: gold;  }
    .el { cursor : pointer; }
    .ok { cursor : default; }
    
    </style>
    <script type="text/javascript">
    
    function changeClass() {
    var mydiv;
    for(var i=1; i<3; i++) {
    mydiv = document.getElementById('pano'+i);
    mydiv.className = "ok";
    }
    }
    </script>
    </head>
    <body>
    <div id="pano1" class="el" > Fareyi buraya getir! </div>
    <div id="pano2" class="el" > Fareyi buraya da getirebilirsin. </div>
    <input type="button" value="click me to change class attribute of the div elements" onclick="changeClass()">
    <br>
    Search Google
    Change HTML class attribute using javascript 
    Javascript Change Style Class of Div tag
    </body>
    </html>
    Last edited by Ayşe; 12-09-2011 at 10:39 AM.

  3. #3
    Join Date
    Jul 2010
    Posts
    28
    Apologies for late reply and many thanks, that seems to have fixed it. Much appreciated !!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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