I have several html elements that I add to the hashes like this:
<p class='message' data-dependencies={'#first':{'equal':'Yes'}}> Relevant Content </p>
so that
$(".message").first().data("dependencies")
returns
{'#first':{'equal':'Yes'}}
But as soon as a friend pointed me, this value is a string. Therefore, of course, the filter described below is difficult to cope with.
The purpose of the filter is to capture elements that have the specified key, in this case "# first".
$el.children().find("*").filter(function(){ var dependency_hash = $(this).data("dependencies"); if(dependency_hash != undefined && "#first" in dependency_hash){ return true } });
Is there a way to access the hash passed through the data object, or is there another way that I can structure the data to execute the same tool that allows me to select items based on the key?
source share