Stop jQuery plugin applying twice to same element
<p>At the moment I'm trying to figure out how use default and custom settings in jQuery plugins. I want to be able to apply the plugin's default settings to elements using a universal class, but additionally customise some of those elements by selecting their ID's instead. Example: <a href="http://jsfiddle.net/srkPT/2/" rel="nofollow">http://jsfiddle.net/srkPT/2/</a> </p>

<pre><code>     &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
        &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
        &lt;head&gt;
        &lt;title&gt;Untitled Document&lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

        &lt;style type="text/css"&gt;
        .box {width:200px; height:200px; padding:50px; margin:40px; border:1px solid; float:left;}​
        &lt;/style&gt;

        &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"&gt;&lt;/script&gt;
        &lt;/head&gt;

        &lt;body&gt;

       &lt;div class="box"&gt;Box 1 - &lt;/div&gt;

    &lt;div id="one" class="box"&gt;Box 2 - &lt;/div&gt;

    &lt;div id="two" class="box"&gt;Box 3 - &lt;/div&gt;

    &lt;div class="box"&gt;Box 4 - &lt;/div&gt;

        &lt;script type="text/javascript"&gt;

    (function($) {


        $.fn.myPlugin = function(params) {

            var defaults = {

                background: '#ddd',

                content: 'foo'

            };

            var params = $.extend(defaults, params);

            return this.each(function() {

                $(this).css('background-color', params.background)

                .append(params.content + ' ');

            }); //RETURN this EACH

        }; //fn myPlugin

    })(jQuery);


        $(function(){

        $('.box').myPlugin();

            $('#one').myPlugin({content:'bar'});

            $('#two').myPlugin({background:'yellow'});

        });//document READY​

        &lt;/script&gt;

        &lt;/body&gt;
        &lt;/html&gt;
</code></pre>

<p>What happens when this runs is that it appends 2 lots of content to #one and #two, and I can understand why; the plugin triggers on all elements with .box (including #one and #two), and then it runs a second time on divs #one and #two, appending the new content on top.</p>

<p>Without changing or running filters on selectors, or adding extra classes to the html, is there any practical way to get around this, so it doesn't apply the plugin twice to the same element? Thanks in advance.</p>

<p><strong>Update</strong></p>

<p>Got this working thanks to a suggestion by czarchaic. Example: <a href="http://jsfiddle.net/srkPT/3/" rel="nofollow">http://jsfiddle.net/srkPT/3/</a></p>

<p>However, it is dependant on the plugin being applied in a specific order. For now, I'm pretty happy, though if anyone can think of a way to get the desired effect regardless of which order it's applied, I'd be most grateful. Thanks to everyone for their help.</p>
