Victor Brumble is writing code again, and this time he's writing a jQuery plugin. His plugin makes alert boxes easy, because Victor loves pointless, modal dialogs.
(function ($) { var settings = { text: 'Thank you for clicking!' }; $.fn.alerter = function (options) { return this.each(function () { if (options) { $.extend(settings, options); } $(this).click(function () { alert(settings.text); }); }); }; })(jQuery);
As you can see, Victor has a default text message associated with his plugin, but he also learned how to use jQuery.extend to allow callers to override the default text. The plugin is working well for Victor, but another developer is complaining about the following code not working correctly.
<p id="p1"> This is paragraph 1. </p> <p id="p2"> This is paragraph 2. </p> <script type="text/javascript"> $("#p1").alerter({ text: "Please don't click again!" }); $("#p2").alerter({ text: "This is not the text you want!" }); </script>
What could possibly be wrong?