Created
April 7, 2011 18:47
-
-
Save plbabin/908413 to your computer and use it in GitHub Desktop.
Small custom jQuery selector that validate if an element has a data attach to himself
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
$.extend($.expr[':'], { | |
hasData: function (obj, intStackIndex, arrProperties) { | |
var arguments = arrProperties[ 3 ]; | |
var $this = $(obj); | |
var isValid = false; | |
if(arguments.indexOf('=') > -1){ | |
arguments = arguments.split('=') | |
if($this.data(arguments[0]) == arguments[1]){ | |
isValid = true; | |
} | |
}else{ | |
if($this.data(arguments)){ | |
isValid = true; | |
} | |
} | |
return isValid; | |
} | |
}); | |
//exemple | |
$('body:hasData("map")'); | |
$('body:hasData("map=4")'); | |
$('body:hasData("events")'); //return true if the element has some events binded to him |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment