Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

changing button text with javascript

Hi,

I have the javascript function below. The line:
document.getElementById(button).innertext = '-';                
isn't working.

What am I doing wrong?

function showhiderow(id,button) {	

	if (document.getElementById) { 
	    
		if (document.getElementById(id).style.display == 'none')
		{
		    document.getElementById(id).style.display = 'block';
		    document.getElementById(button).innertext = '-';		    
		}
		else
		{				
		    document.getElementById(id).style.display = 'none';
		}
	}	
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
check this also
document.getElementById(button).innerHTML= '-';
It depends where the button label is written.

<button type="button" id="myButton2">Button Label</button>  
    - .innerHTML or better    .childNodes[0].nodeValue

or

<input type="button" value="Button Text" id="myButton1"></input>
   - .value

http://www.permadi.com/tutorial/jsInnerHTMLDOM/index.html
Avatar of A_Nilsson
A_Nilsson

Hi,

I believe that you should use document.getElementById(button).value instead ov document.getElementById(button).innertext .

Good luck!