简体   繁体   中英

Prevent application of a class in jquerymobile

How can I force ui-btn-active never to be set anywhere? Listening for events seems very bloaty since I don't really know where it is applied.

Searching online I only found very outdated solutions.

You can remove the class in JS on mobileinit

$(document).on("mobileinit", function () {
   $.mobile.activeBtnClass = "";
});

Partly an answer..

You could overwrite the original $.fn.addClass method and remove the className before calling the original addClass:

var _org = $.fn.addClass;
$.fn.addClass = function(className) {

  className = className.replace(/\bui-btn-active\b/g, '');

  return _org.call(this, className);
}

This will not protect you against:

el.className = 'ui-btn-active';
$(el).html('<div class="ui-btn-active"></div>');
el.classList.add('ui-btn-active');
el.innerHTML = '<div class="ui-btn-active"></div>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM