Skip to content

Instantly share code, notes, and snippets.

@boblauer
Last active December 22, 2015 11:59
Show Gist options
  • Select an option

  • Save boblauer/6469430 to your computer and use it in GitHub Desktop.

Select an option

Save boblauer/6469430 to your computer and use it in GitHub Desktop.

Revisions

  1. boblauer renamed this gist Sep 6, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. boblauer created this gist Sep 6, 2013.
    42 changes: 42 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    (function() {
    var affected = [], unaffected = [],
    className;

    className = prompt('Class to check:');
    if (!className) return;

    $('.' + className).each(function() {
    var element = this,
    $element = $(this),
    before = [], after = [];

    var styleProps = Object.keys(JSON.parse(JSON.stringify(element.style)));

    var before = [], after = [];

    styleProps.forEach(function(style) {
    before.push($element.css(style));
    });

    $element.removeClass(className);

    styleProps.forEach(function(style) {
    after.push($element.css(style));
    });

    $element.addClass(className);

    if (before.join('') === after.join('')) {
    unaffected.push(element);
    }
    else {
    affected.push(element);
    }
    });

    console.log(affected.length + ' element(s) DO have styles applied from the ' + className + ' class.');
    affected.forEach(function(el) { console.log(el); });

    console.log(unaffected.length + ' element(s) do NOT have styles applied from the ' + className + ' class.');
    unaffected.forEach(function(el) { console.log(el); });
    })();