The title looks a little confusing, so let me show an example:
Markup
<div id="MyDiv"></div>
<div id="SecondaryDiv"></div>
JS
// Set the HTML5 data key 'name' to value 'MyName'
$("#MyDiv").data("name", "MyName");
// Return all divs with the data key 'name' matching 'MyName'
// This works without a hitch
$("div").filter(function () {
return $(this).data("name") === "MyName";
});
// This breaks because I try to add '.toLowerCase()' to the end of the .data() function.
// The error returned is:
// TypeError: $(...).data(...) is undefined
$("div").filter(function () {
return $(this).data("name").toLowerCase() === "myname";
});
How can I ignore case when comparing $(...).data(...)
values?
As a side note, even if I do this:
// This throw an error saying:
// TypeError: val is undefined
var val = "";
$("div").filter(function() {
val = $(this).data("name");
return val.toLowerCase() === "myname";
});