I am trying to use each function, but I need to match the exact attribute name
jquery
$('[data*="name"]').each(function(i, obj){dostuff}
I need to {dostuff} only when name is found and not when names is found.Any suggestions ?
I am trying to use each function, but I need to match the exact attribute name
jquery
$('[data*="name"]').each(function(i, obj){dostuff}
I need to {dostuff} only when name is found and not when names is found.Any suggestions ?
remove the *
$('[data="name"]').each(function(i, obj){dostuff}
according to the Documentation the * matches also substrings, so just remove it if you don't need :)
I think you should do it in that way.
$('[data="name"]').each(function(i, obj){ dostuff });
I hope I have helped you! :)
You should be able to just use the attribute equals selector, which is basically identical to your current selector sans the *
(as *=
is used as a "contains" selector) :
// This would perform your operation to every element that had a data attribute of
// "name" (i.e. <span data="name">, etc.)
$('[data="name"]').each(function(i, obj){
dostuff();
});
Just
$('[data="name"]').each(function(i, obj){dostuff}
OR
$('[data*="name"]:not([data*=names])').each(function(i, obj){dostuff}
Remove the "contains" condition from the attribute selector (the * character)
$('[data="name"]').each(function(i, obj){dostuff}
Using the * after the attribute name
Selects elements that have the specified attribute with a value containing a given substring
Read here