my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Change in the text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Change in the text" Watch "Change in the text" New topic
Author

Change in the text

Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 95
Dear all,

Below is the code I am using


The code actually hides the content of the table when the image is clicked. and displays the content when the image is again clicked. What I want is the change in the text next to that, it should say Hide Table when the content of the table is displayed and Show Table when the content of the table is hidden. How do I go about doing this? need some ideas.
Thanks


SCJP 6.0
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Isolate the text to be manipulated in a <span> and then use innerHTML to change its contents.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

P.S <b> is outdated. Use CSS.
Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 95
Bear Bibeault wrote:Isolate the text to be manipulated in a <span> and then use innerHTML to change its contents.


Can you please elaborate on the part on how to use innerHTML to change the contents?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Get a reference to the element and set its innerHTML property to whatever you want.
Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 95
Dear Bear,

As you have suggested I have isolated the text in the span tag





I am still not able to understand when you said get reference to element and change its innerHTML, when you said reference to element which one did you mean? should i write javascript..I am kind of totally confused, please give me some examples..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

I'm not sure what you are trying to do with the hide and show classes.

Give the span element an id so you can reference it. Such as:

Then, to change its content:

To show:
To hide:
Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 95
Dear Bear,

Thanks a lot for explaining it step by step. It helped me solve the problem.

Thanks.
 
 
subject: Change in the text