Stephen's dev blog

jQuery create a simple plugin

Posted on: 11 August, 2008

  • In: Tutorials
  • Comments Off on jQuery create a simple plugin

This is just a quick tutorial (more of a code snippet) for creating a very simple plugin for jQuery.

Of course, there are lots of tutorials around for this, this is mainly for reference 🙂

$.fn.myFunction = function()
    // use the following loop to iterate through all objects
    // returned by the jQuery selector which was used
    return this.each(function()
        // here we can access any properties using
        // the normal jQuery selectors

So this function alerts the HTML of the selected element(s) and adds a new class ‘red’. You can then call the new function using:


Another example of how easy and powerful jQuery is 🙂 Look here for more information.

Tags: ,

  • None
  • Patrick: I changed my code, but now I have another problem: Fatal error: Call to a member function isAvailable() on a non-object in /var/www/vhost/web/shopA
  • Stephen Gray: Hi Patrick, That first error is my fault. I had the method name for the refund() method as void() as I had copied the code from the other method!
  • Patrick: Hi Stephen, thanks for sharing your knowledge about creating a custom payment module. I need an extension for magento to handle a credit card payme


%d bloggers like this: