SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    toggling getElementByClassName problem

    Where am I going wrong in this?
    Error: obj.style has no properties
    Source File: showbook.php?keyword1=What%20have&keyword2=thou%20Son%20of%20God&keyword3=to%20do%20with%20thee&keyword4=swine&keyword5=devil&keyword6=torment
    Line: 151
    Code:
    //http://javascript.about.com/library/bldom08.htm
    document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
    };
    		
    function Toggle(item) {
       obj=document.getElementsByClassName(item);
       visible=(obj.style.display!="none") //Line: 151
       key=document.getElementById("x" + item);
       if (visible) {
         obj.style.display="none";
         key.innerHTML="[+]";
       } else {
          obj.style.display="block";
          key.innerHTML="[-]";
       }
    }
    and
    Code:
    <div ID="support" style="display:none; margin-left:2em">
    	<span class='forForum' style='display:none; font-weight: bold;'>[quote]</span>
    <span class='forForum' style='display:none; font-weight: bold;'></span> :<span class='forForum' style='display:none; font-weight: bold;'></span><br />...
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I think it should be:
    Code:
    visible=(obj.style.display!="none") ? 1 : 0; //Line: 151
    as you are assigning the value to the variable then checking the variable later
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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