If you're a developer (you are reading this so you are) you've used jQuery to access different elements from a page.

It is super convenient to set data attributes to given HTML elements.
For example:

You can use jQuery to loop through all of the containers with 'app_container' class but how are you going to
tell which one you're currently processing? yes, you can use element's ID for that but if we want to put more data into that element we can achieve id using data attributes which can be accessed like so:

var id = $('app_container').prop('id');
var type = $('app_container').data('type');

Here is a PHP class that allows you to create HTML attributes from a php array.
If you pass the second parameter the key will be prefixed with 'data-' prefix so they can be access via jQuery later.

Here is a link to the gist: https://gist.github.com/lordspace/fcc733e7e2a53ef427c3

Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer