File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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: 61433
    
  67

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: 61433
    
  67

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: 61433
    
  67

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: 61433
    
  67

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.
 
Consider Paul's rocket mass heater.
 
subject: Change in the text