Web Analytics Made Easy -
StatCounter toggler object - CodingForum

Announcement

Collapse
No announcement yet.

toggler object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • toggler object

    Hi,
    I'm trying to create a toggler object. Its my first stab at object oriented javascript. I've basically got two functions that I've put together to manipulate an anchor. Its not working but i don't think i'm that far off. It just shows and hides a div whilst changing the link text at the same time.

    Code:
    function toggler(element, layerid, newtext) {
    var layerid = document.getElementById('info');
    
    function showhide(layerid){
    if(layerid.style.display == "none"){
    layerid.style.display = "block";
    }
    else{
    layerid.style.display = "none";
    }
    }
    
    var originaltext = element.innerHTML;
    
    function replacetext() {
     if(element.innerHTML == originaltext){
     element.innerHTML = newtext;
    }
    else{
    element.innerHTML = originaltext;
    }
    }
    
    }
    html:
    Code:
    <a id="toggle" href="javascript:toggler(this 'info', 'close')">Find out more</a></p>
    If anyone could point me in the right direction, or simply tell me i'm a long way of understanding object oriented javascript, that would be great.
    99 times out of 10!
Working...
X