My evil jQuery Plugin

This post is more than 2 years old.

I demonstrated this at my jQuery presentation earlier today at CFUNITED but I thought I'd share the code. The basic idea is this - you have a coworker you hate (we've all had one from time to time), so you quickly figure out their IP and output some code just for them:


<head> <script type="text/javascript" src=""></script> <script src="myplugin.js"></script> <script> <cfif cgi.remote_host is ""> function mean() { $("#content").notMean(); }

$(document).ready(function () { window.setInterval('mean()',5000) }) </cfif> </script> </head>


<div id="content"> This is my text. It is only my text. It does not have anything special in it. You should not read it. </div>

</body> </html>

What does the 'notMean' plugin do? I think a video demonstration may be a bit nicer.

Be sure to watch the entire thing - it is a bit subtle. So I don't imagine anyone would ever use this in production (but if you do, let me know), but here is the source code:

$.fn.notMean = function(){ this.each( function(){ var contents = $(this).html() var ranPos = Math.ceil(Math.random() * contents.length) var ranChar = Math.ceil(Math.random() * 26) + 65 var newChar = String.fromCharCode(ranChar) if(Math.random() > 0.5) newChar = newChar.toLowerCase() var newContents = contents.substring(0,ranPos) + newChar + contents.substring(ranPos+1,contents.length) $(this).html(newContents) } )
return this



Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA