Josh Josh - 1 year ago 89
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 ?

Answer Source

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){ 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download