clearing onlclick event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Cruys
    New Member
    • May 2011
    • 1

    #1

    clearing onlclick event

    Hi there, I used the following 2 functions to change the text on a button and open a hidden div at the same. I want to revert back to the original text on the button (read more..) when I click to close the div again.

    Please help :D

    Code:
    function onclick(){
    	javascript:readmore('text1')
    }
    
    function valChange(){
        document.myForm.myButton.value="...reduce text"
    }
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    make a new function that restores the original Text and interchange the two handlers each time the button is pressed.

    ex.
    Code:
    function changeVal()
    {
        this.value = "… reduce text";
        this.removeEventListener("click", changeVal, false);
        this.addEventListener("click", changeValBack, false);
    }
    function changeValBack()
    {
        this.value = "… read more";
        this.removeEventListener("click", changeValBack, false);
        this.addEventListener("click", changeVal, false);
    }
    // button is the reference to the button element
    button.addEventListener("click", changeVal, false);

    Comment

    Working...