Skip to content

$.custom()

Arthur Guiot edited this page Jul 5, 2017 · 1 revision

How does it work?

Do you like the $.var() or the $.target() function? Do you want to create a function that will basically interact with an element, depending on their HTML tags? Well, the $.custom() function is made for you.

You simply need to give it the target attribute, the function to apply to each element and the push time (optional).

How to use it?

For the example, we'll recreate the $.var() function. Here is how we'll do it:

JS:

// Creating $varEmulation, with arguments the domain (most of the cases it will be window) and the push time.
function $varEmulation (domain, push) {
   // custom function with for arguments: targetAttr = "var", callback = function (element, attr) { ... } (see below), push = push
   $.custom("var", function(element, attr) {
       // from the current element, replace it's HTML by the variable written in the var="..." attribute
       element.innerHTML = domain[attr];
   }, push)
}

⚠️ Questions?

Don't hesitate to ask your questions ⁉️ in the issue part 😁

Clone this wiki locally