Getting a regular expression from a string in JavaScript is quite simple: new RegExp('Hello Universe'); # => /Hello Universe/ You can also use special characters: new RegExp('^(\\d+) users') # => /^(\d+) users...
When you need to check a value for presence, don't rely on JavaScript since it considers 0 or "0" false. Also don't rely on LoDash's _.isEmpty:
Having a unique selector for an element is useful to later select it from JavaScript or to update a fragment with an Unpoly. Haml lets you use square brackets ([]) to...
Compress and obfuscate Javascript code online completely free using this compressor...
Some modern Javascript APIs return iterators instead of arrays. In plain Javascript you can loop through an iterator using for...of: var iterator = ...; for (var value of iterator) { console.log(value...
...someone reloads a form by pressing enter/return in the URL field, or by opening JavaScript links incorrectly. The attached initializer provides a default way to deal with this.
validate( "email".is("required").andIsAn("email") );
Attached (see below) is some code to allow using unobtrusive JavaScript on pages fetched with an AJAX call. After you included it, you now do not use the usual
...unobtrusive() to register new element activation callbacks $.unobtrusive = function(callback) { $(document).on('activate-unobtrusive-javascript', function(event, root) { $(root).each(callback); }); } // Define a function for all jQuery collections to manually...
If you manipulate the DOM with JavaScript and your page contains nested elements with position: relative, chances are Internet Explorer 7 will not properly move to the right position.
...nest. This is often impossible, though. Force the correct redrawing of the elements using JavaScript. Adding a bogus class ($(element).addClass('touch')) seems to suffice. Try to give the offending...
Use the click method on the DOM element: let link = document.querySelector('a') link.click()
You can say: $(element).is(':visible') and $(element).is(':hidden') jQuery considers an element to be visible if it...
Imagine all the syntactical delights of Ruby and Haml for your JavaScript. You write in a nice language, but get normal JavaScript at runtime. All whilst having full access to...
...3rd-party JavaScript libraries (jQuery, PrototypeJS), debugging support (it becomes pure, readable JavaScript), existing support from test suites (it’s normal JavaScript) and growing support from various text editors (TextMate...
...a Firefox extension but there is also a "Lite" version which runs purely off JavaScript. Though all major browsers offer inspection tools you may like the Firebug style. Also, for...
Get the bookmarklet over at http://getfirebug.com/firebuglite#Stable. It usually loads the JavaScript code from a remote server but you can also download it to have it run...
The NestedHash class allows you to read and write hashes of any depth. Examples: hash = {} NestedHash.write hash, 'a', 'b', 'c...
I use the TypeScript compiler for this, since its output is more minimal than Babel's. The following will transpile...
...not necessarily a link or button, but could be any HTML element with a Javascript event binding. The easiest way to get this step is to use Spreewald. If you...
Search engines, such as Google and Bing are engineered to crawl static web pages, not javascript-heavy, client-side apps. This is typical of a search engine which does not...
...render javascript when the search bot is crawling over web pages. This is because our javascript-heavy apps need a javascript engine to run, like PhantomJS or v8, for instance...
...After trying jQuery's trigger to no avail, I had success by using native Javascript methods to create and dispatch an event. For instance, to trigger a mousedown event:
JavaScript engines such as Google’s V8 (Chrome, Node) are specifically designed for the fast execution of large JavaScript applications. As you develop, if you care about memory usage and...
...aware of some of what’s going on in your user’s browser’s JavaScript engine behind the scenes...
...they forgot one very important part, the ability to use it when responding to JavaScript (JS) requests! In Rails 3.1 it’s incredibly easy to build your application’s JavaScript...
...an AJAX request to your application you can only write your response using regular JavaScript and not CoffeeScript, at least until CoffeeBeans came along...
...for the given label, then checks if that field is hidden via CSS (or Javascript). It is not currently tested if the label is visible or hidden. For this see...
ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object...
If you want a class-like construct in JavaScript, you can use the module pattern below. The module pattern gives you basic class concepts like a constructor, private state, public...
Since the module pattern only uses basic JavaScript, your code will run in any browser. You don't need CoffeeScript or an ES6 transpiler like Babel. A cosmetic benefit...
Amazing guide how to divide a ball of Javascript spaghetti distinct separate layers (model, view, controller, backend adapter). It does not use a Javascript framework...