js: Add new jQuery plugin `getData()`

This commit is contained in:
Johannes Meyer 2019-07-29 15:58:41 +02:00
parent 9e3c9bbab7
commit 27cd34dd2d
1 changed files with 10 additions and 0 deletions

View File

@ -5,6 +5,16 @@
'use strict';
/* Get data value or default */
$.fn.getData = function (name, fallback) {
var value = this.data(name);
if (typeof value !== 'undefined') {
return value;
}
return fallback;
};
/* Whether a HTML tag has a specific attribute */
$.fn.hasAttr = function(name) {
// We have inconsistent behaviour across browsers (false VS undef)