Skip to content

Instantly share code, notes, and snippets.

@hayatbiralem
Last active June 24, 2020 14:18
Show Gist options
  • Save hayatbiralem/c9e12ab1257592111fdc54f96d281ebb to your computer and use it in GitHub Desktop.
Save hayatbiralem/c9e12ab1257592111fdc54f96d281ebb to your computer and use it in GitHub Desktop.
Mark selectors has tags
(function ($) {
$(document).ready(function(){
var selectorMap = {
'div': ['h2', 'h3', 'h4'],
'.some-class': ['h2', 'h3', 'h4']
};
var prefix = 'has-';
var prefixDirect = 'has-direct-';
$.each(selectorMap, function(selector, tags){
$.each(tags, function(tagIndex, tag){
$(selector).each(function(){
var $wrapper = $(this);
$wrapper.toggleClass(prefix + tag, $wrapper.find(tag).length > 0);
$wrapper.toggleClass(prefixDirect + tag, $wrapper.find('>' + tag).length > 0);
});
});
});
});
})(jQuery);
@hayatbiralem
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment