Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: simple text change onclick script?..anyone help?!

  1. #1
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default simple text change onclick script?..anyone help?!

    i am looking for a simple script that simply changes the text when you click it.
    ie

    "click here for answer"

    when you click on it it changes to

    "the answer"

    and when you click on it again it changes back to

    "click here for answer"

    hopefully there is a script somewhere (that works on all browsers) i think it might be quite a basic one?
    can anyone body point me in the right direction? thanks!
    Last edited by svenaldo; 04-24-2011 at 03:48 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    While this isn't exactly what you asked for, I think you might think it fits the situation better: http://css-tricks.com/video-screenca...accessibility/

    If it doesnt, tell me and I'll whip up something.
    Jeremy | jfein.net

  3. #3
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    its gonna take a while for that to download (slow connection here)

    i just want something exactly the same as this

    http://chinesepod.com/lessons/sample/newbie/dialogue

    where is says (show translation)

    like all the show content/hide content scripts out there but without the content or need for expanding.

    i keep finding examples but they are often old and not working on every browser. I will have quite a few on each page on the website.

    great if you can help me or point me to where there is a standard script!
    Last edited by svenaldo; 04-21-2011 at 07:26 PM.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try:
    Code:
    <script type="text/javascript">
    var reveal = function(_new, me){
        var _old = me.innerHTML;
        me.innerHTML = _new;
        me.onclick = function(){
            reveal(_old, this);
        };
    };
    </script>
    <a href="javascript:void(0);" onclick="reveal('Not much, how about you?', this);">Hey, what's up!?</a>
    Jeremy | jfein.net

  5. #5
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Nile.

    Thank you very very much. This is exactly what I was looking for! You are a star!

    As I will be using this a lot is it necessary to give each one a specific id.

    I am just worried about browser errors now and in the future?!

    Thanks again you have really helped me out.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No - were do you see an id?
    Jeremy | jfein.net

  7. #7
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I know there is no id at the moment.

    I was just wondering if I needed to add that into it as I will be using quite a few of them on the same page and I have seen quite a few websites (like the example in my above post)
    that uses unique ID's for each one. So i was just checking that I didn't need that here. I am just scared about it causing problems or crashing down the line when I have used it hundreds of times.

    (sorry i'm still a newbie with the javascript! )

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No, just make sure the second parameter of the reveal() is this.
    Jeremy | jfein.net

  9. The Following User Says Thank You to Nile For This Useful Post:

    svenaldo (04-22-2011)

  10. #9
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thanks again. this script is uber useful for me!

  11. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved wh sen an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •