Created
August 26, 2014 09:59
-
-
Save davidmars/ede0c77f3e8422961658 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* For slackers... Quick methos selectors pluggin dealing with attribute names and values. | |
* @author David Marsalone | |
* @example $(".myslector").findByAttr("my-attribute-name","my attribute value"); | |
* @example $(".myslector").filterByAttr("my-attribute-name","my attribute value"); | |
*/ | |
(function ( $ ) { | |
/** | |
* Quick method to get the descendants of each element in the current set of matched elements, filtered by an attribute name and its value | |
* @param {string} attributeName The attribute name you are looking for. | |
* @param {string} attributeValue The attribute value you are looking for. | |
* @returns {jQuery} | |
*/ | |
$.fn.findByAttr = function(attributeName,attributeValue) { | |
return this.find("["+attributeName+"='"+attributeValue+"']"); | |
}; | |
/** | |
* Reduce the set of matched elements to those that match the given attribute name and its value | |
* @param {string} attributeName The attribute name you are looking for. | |
* @param {string} attributeValue The attribute value you are looking for. | |
* @returns {jQuery} | |
*/ | |
$.fn.filterByAttr = function(attributeName,attributeValue) { | |
return this.filter("["+attributeName+"='"+attributeValue+"']"); | |
}; | |
}( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment