Josh Josh - 5 months ago 9x
Javascript Question

match exact attribute name in jquery

I am trying to use each function, but I need to match the exact attribute name


$('[data*="name"]').each(function(i, obj){dostuff}

I need to {dostuff} only when name is found and not when names is found.Any suggestions ?


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){