JQuery best practice, using $(document).ready inside an IIFE?

No, IIFE doesn’t execute the code in document ready. 1. Just in IIFE: (function($) { console.log(‘logs immediately’); })(jQuery); This code runs immediately logs “logs immediately” without document is ready. 2. Within ready: (function($) { $(document).ready(function(){ console.log(‘logs after ready’); }); })(jQuery); Runs the code immediately and waits for document ready and logs “logs after ready”. This … Read more

Override jQuery .val() function?

You can store a reference to the original val function, then override it and do your processing, and later invoke it with call, to use the right context: (function ($) { var originalVal = $.fn.val; $.fn.val = function(value) { if (typeof value != ‘undefined’) { // setter invoked, do processing } return originalVal.call(this, value); }; … Read more

Click the poster image the HTML5 video plays?

This is working for me Andrew. In your html head add this small piece of js: var video = document.getElementById(‘video’); video.addEventListener(‘click’,function(){ video.play(); },false); Or, just add an onlick attribute directly to your html element: <video src=”https://stackoverflow.com/questions/5278262/your_video” width=”250″ height=”50″ poster=”your_image” onclick=”this.play();”/>

scrolltop with animate not working

You have to use $(‘html,body’) instead of $(window) because window does not have a scrollTop property. $(‘#scroll-bottom’).on(‘click’, function() { $(‘html, body’).animate({ scrollTop: 2000 }, 2000); // for all browsers // $(‘html’).animate({scrollTop: 2000}, 2000); // works in Firefox and Chrome // $(‘body’).animate({scrollTop: 2000}, 2000); // works in Safari }) #top { margin-bottom: 2000px; } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> … Read more

jQuery: keyup for TAB-key?

My hunch is that when you press the tab key, your form’s input loses focus, before the keyup happens. Try changing the binding to the body, like this: $(‘body’).keyup(function(e) { console.log(‘keyup called’); var code = e.keyCode || e.which; if (code == ‘9’) { alert(‘Tab pressed’); } }); Then, if that works (it does for me) … Read more