View Full Version : Resolved simple text change onclick script?..anyone help?!
svenaldo
04-21-2011, 06:32 PM
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!
While this isn't exactly what you asked for, I think you might think it fits the situation better: http://css-tricks.com/video-screencasts/51-a-lesson-learned-in-accessibility/
If it doesnt, tell me and I'll whip up something.
svenaldo
04-21-2011, 07:19 PM
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!
Try:
<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>
svenaldo
04-22-2011, 05:07 AM
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. :)
No - were do you see an id?
svenaldo
04-22-2011, 05:26 AM
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! )
No, just make sure the second parameter of the reveal() is this.
svenaldo
04-22-2011, 06:23 AM
thanks again. this script is uber useful for me!
No problem, I'm glad to help :D
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"
svenaldo
04-24-2011, 03:48 AM
done. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.