Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.getElementById('ImgId').className

    When using instead of this line (to change style of element)
    document.getElementById('ImgId'').style.visibility = "visible";

    one would use (to change class of element)


    Does className change the class="imgHidden" into "makeImgVisible" here?
    Code:
    document.getElementById('ImgId').className = "makeImgVisible";
    
    .imgHidden {visibility:hidden;}
    .makeImgVisible {visibility:visible;}
    
    
    <img src="myImg.jpg" alt="" id="ImgId" class="imgHidden" width="200" height="200">
    Last edited by _com; 07-11-2005 at 05:42 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by _com
    Does className change the class="imgHidden" into makeImgVisible" here?
    Yep. (You could have easily tried it to find out )

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for confirming this. Maybe interesting link:


    <http://www.quirksmode.org/dom/classchange.html>


    Another thing:

    Code:
    document.getElementById('lemons').className = "makeImgVisible";
    document.getElementById('apples').className = "makeImgVisible";
    document.getElementById('grapes').className = "makeImgVisible";
    document.getElementById('blueberries').className = "makeImgVisible";
    Can you make an iteration so I need not repeat if using same styles over and over again ??
    Last edited by _com; 07-11-2005 at 05:53 PM.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Can you make an iteration so I need not repeat if using same styles over and over again ??
    Again, the answer lays within your question. Yes, you may do that:
    PHP Code:
    var ids=['lemons','apples','grapes','blueberries'];
    for(var 
    i=0;i<ids.length;i++){
    document.getElementById(ids[i]).className "makeImgVisible";

    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Again, the answer lays within your question. Yes, you may do that:
    Thank you for helping out. The array syntax did not use that much, thanks for refreshing.

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Than you may use DOM methods, geting the elements by their indexes, if grouping exclusive in a neutral parentNode (a div)

    var imgs = document.getElementById('cont').getElementsByTagName('img');
    for(var i=0;i<imgs.length;i++){
    imgs[i].className='makeImgVisible';
    }
    ...
    ...
    <div id="cont">
    <img src="lemons.jpg">
    <img src="apples.jpg">
    <img src="grapes.jpg">
    <img src="blueberries.jpg">
    </div>
    Last edited by Kor; 07-12-2005 at 01:59 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <div id=""></div>
    <div id=""></div>
    <div id=""></div>
    <div id=""></div>

    It is like this in my page so your first post indicated

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    edit

    <div id=""></div>
    <div id=""></div>
    <div id=""></div>
    <div id=""></div>

    It is like this in my page so your first post indicated ...
    Last edited by _com; 07-12-2005 at 02:24 PM. Reason: edit


  •  

    Posting Permissions

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