Created
July 24, 2012 16:06
-
-
Save corbanbrook/3170892 to your computer and use it in GitHub Desktop.
jQuery :inlineStyle selector filter extention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
:inlineStyle filter | |
An inline style selector filter. | |
Usage: $("div:inlineStyle(display:none)"); // returns any divs with display style set to none | |
$("div:inlineStyle(width)"); // returns any divs with a width style set | |
$("div:inlineStyle"); // returns any divs with an inline style set | |
Written by Corban Brook @corban | |
*/ | |
$.expr[':'].inlineStyle = function(element, index, meta) { | |
var $element = $(element); | |
var style = $element.attr("style"); | |
var match = meta[3]; | |
var matchSelector, matchValue, value; | |
// Only interested in elements with an inline style set. | |
if (!style || style === "") { | |
return false; | |
} | |
if (match) { | |
if (match.indexOf(":") > 0) { | |
var pair = match.split(":"); | |
matchSelector = pair[0]; | |
matchValue = pair[1]; | |
} else { | |
matchSelector = match; | |
} | |
value = element.style[matchSelector]; | |
if (typeof value === "undefined" || value === "") { | |
return false; | |
} | |
// Match param given, make sure this style exists and check vs match value if specified | |
return typeof matchValue !== "undefined" ? value === matchValue : true; | |
} else { | |
// No match param given, return true for elements which have any inline styles set | |
return true; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment