Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

How Do You Make Text In A <div> Change When You Click On A Link?


7 replies to this topic

#1 electriic ink

    "Britons never never shall be slaves." As true now as it was in 1740.

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,262 posts
  • Gender:Male
  • Location:Heaven
  • Interests:Promotion: Aug 4 2005 8.24pm BST
  • myCENT:74.43

Posted 24 July 2006 - 03:11 PM

Say I have a link and some text. How would I make it so that when I clicked on the link, that text changed?

#2 electron

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 162 posts

Posted 25 July 2006 - 03:22 AM

Thats pretty easy.
Use the getElementById() function of Java Script.
Then Change the text by using innerHTML function.

If you want to call it by anchor call a function which does the above thing.

#3 electriic ink

    "Britons never never shall be slaves." As true now as it was in 1740.

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,262 posts
  • Gender:Male
  • Location:Heaven
  • Interests:Promotion: Aug 4 2005 8.24pm BST
  • myCENT:74.43

Posted 25 July 2006 - 02:57 PM

Thanks electron but after some researching it appears that innerHTML is an IE thing. Is there any function which cross-browser compatible? Thanks....

#4 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:86.16

Posted 25 July 2006 - 07:12 PM

innerHTML works for me, and i'm using Opera.
<input type="button" value="Click" onclick="document.getElementById('a').innerHTML='newtext'"/>
<span id="a">text</span>


#5 electriic ink

    "Britons never never shall be slaves." As true now as it was in 1740.

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,262 posts
  • Gender:Male
  • Location:Heaven
  • Interests:Promotion: Aug 4 2005 8.24pm BST
  • myCENT:74.43

Posted 25 July 2006 - 07:28 PM

It works for firefox as well. :) Oh well, guess you can't believe half of what you read on the internet. Maybe it had Microsoft origins or something.

Thank you electron and truefusion....

#6 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 24 March 2010 - 07:14 AM

Thanks that really helped me

-reply by charles

#7 Guest_Sunil_*

  • Guests

Posted 18 March 2011 - 03:52 PM

I want do same using css and html coz I want it in Outlook mail which dows not support javascript. Please Help me

#8 Guest_danielle_*

  • Guests

Posted 03 May 2011 - 08:50 PM

Is there a way to do this within a DIV rather than a form item? I need to use HTML and have the updated text realise this:

function Web1()
{
var MyElement = document.getElementById("MyTextBox");
MyElement.value = "<h2>header</h2><p>text2</p>";

return true;
}

thanks




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users