Fandom

Community Central

Admin Forum:Censoring spoiler with jQuery

19,002pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This Forum has been archived

Forums: Admin Central Index Technical Help Censoring spoiler with jQuery
Central's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Note: This topic has been unedited for 1357 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.


Below is the coding to show/hide text with spoilers:

$(function() {
	$('.spoilerContent').click(function() {
		$(this).andSelf().fadeTo(1000,1);
		$(this).prev('.spoiler').fadeTo(1000,0);
	return false;
	});
});
<span class="spoiler" style="position:absolute">This section contains spoilers.</span>
<span class="spoilerContent" style="opacity:0">Spoiler spoiler spoiler spoiler......</span>

I got the text to appear on clicking, but on second click it doesn't get back, despite return false. What's wrong with this code and how can I fix it?  Cafeinlove msg 2012.06.11. 20:47 (UTC)

Finally I found a solution.
var oddClick = true;
	$('.spoilerContent').click(function(){
		$(this).andSelf().fadeTo(1000, (oddClick) ? 1 : 0);
		$(this).prev('.spoiler').fadeTo(1000, (oddClick) ? 0 : 1);
	oddClick = !(oddClick);
});
 Cafeinlove msg 2012.06.12. 07:21 (UTC)
Oh that's fantastic. I won't copy it because I might want to do something slightly different. But still; thanks for the idea! :D STARFLEET ACADEMY 08:10, June 12, 2012 (UTC)

Also on Fandom

Random Wiki