Why return this.each(function()) in jQuery plugins?
When you filter elements with a selector ($(‘.myclass’)), it can match more than only one element. With each, you iterate over all matched elements and your code is applied to all of them.
When you filter elements with a selector ($(‘.myclass’)), it can match more than only one element. With each, you iterate over all matched elements and your code is applied to all of them.
Fancybox currently does not directly support a way to automatically launch. The work around I was able to get working is creating a hidden anchor tag and triggering it’s click event. Make sure your call to trigger the click event is included after the jQuery and Fancybox JS files are included. The code I used … Read more
src/ stands for source, and is the raw code before minification or concatenation or some other compilation – used to read/edit the code. dist/ stands for distribution, and is the minified/concatenated version – actually used on production sites. This is a common task that is done for assets on the web to make them smaller. … Read more
You need to make sure that your request is a POST request. Not a get request. See this answer to find out more about why: How to let an ASMX file output JSON
Assigning a unique ID would be the job of the template parser. You don’t mention which templating engine you’re using. The general idea is that you pass the dropdown data, along with a reference to the template you defined above, to the template parser. The parser will inject the id values into the correct template … Read more
How about: var __picker = $.fn.datepicker; $.fn.datepicker = function(options) { __picker.apply(this, [options]); var $self = this; if (options && options.trigger) { $(options.trigger).bind(“click”, function () { $self.datepicker(“show”); }); } } Usage: $(“#date”).datepicker({ trigger: “#button” }); $(“#date2”).datepicker({ trigger: “#button2” }); Example: http://jsfiddle.net/gduhm/ Or, less intrusively with your own jQuery plugin: $.widget(“ui.datepicker2”, { _init: function() { var $el … Read more
You can do this by providing a function to the source option of autocomplete: var availableTags = [ /* Snip */]; function split(val) { return val.split(/@\s*/); } function extractLast(term) { return split(term).pop(); } $(“#tags”) // don’t navigate away from the field on tab when selecting an item .bind(“keydown”, function(event) { if (event.keyCode === $.ui.keyCode.TAB && … Read more
If you are using the html5 audio tag, there is the “onended” event handler. I don´t know if the browsers support it yet. Something like: <audio src=”https://stackoverflow.com/questions/4619917/xpto.mp3″ onended=”DoSomething();”></audio> In the last case you can use a swf that can play the sound, and alert your javascript when it reaches the end.
Stefano J. Attardi wrote a nice jQuery plugin that just does that. It is more stable than Robert’s and also fades to a lighter grey when the field gets focused. See the demo page Grab it on GitHub Play with the fiddle I modified his plugin to read placeholder attribute as opposed to manually creating … Read more
Run the code snippet to see it work $(‘input.number’).keyup(function(event) { // skip for arrow keys if(event.which >= 37 && event.which <= 40) return; // format number $(this).val(function(index, value) { return value .replace(/\D/g, “”) .replace(/\B(?=(\d{3})+(?!\d))/g, “,”) ; }); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js”></script> <input class=”number”>