Curtis Timson

Front End & .NET Developer

Category

jQuery

Namespacing jQuery event handlers

If we are to attach 2 or more event handlers to an element these will become stacked and run linear in the order they were attached. For example: $(“.foo”).on(“click”, function(e){ console.log(“bar”); }); $(“.foo”).on(“click”, function(e){ console.log(“baz”); }); If .foo is then… Continue Reading →

Understanding jQuery data() storage

It is a common misunderstanding that .data(“key”) is simply a shortcut for .attr(“data-key”). .data() does read HTML5 data attributes, but this is only the first time it is called, as per the documentation: The data- attributes are pulled in the… Continue Reading →

Creating a new rule for a CSS class in jQuery

In jQuery, to add a new style to all elements which have a particular CSS class, we can simply call a function like the following: <div class=”foobar”>Lorem Ipsum</div> <div class=”foobar”>Dolor sit amet</div> function SetFooBarRed(){ $(“.foobar”).css(“background-color”, “red”); } This will add… Continue Reading →

Using jQuery callback functions

I’ve heard questions in the past regarding how to run a script after a jQuery animation or event has been completed. The majority of these believe that you need to delay the script for a few seconds, allowing the animation… Continue Reading →

© 2017 Curtis Timson — Powered by WordPress

Theme by Anders NorenUp ↑