I'm not too familiar with JS, so just three generic notes:
It seems to me that the
elements[i].attributes.length > 0
check is unnecessary because the statements inside the followingfor
loop won't ifelements[i].attributes.length
is zero.Consider creating local variables for
elements[i]
andelements[i].attributes
. It would remove some duplication.for (var i = 0; i < elements.length; i++) { var currentElement = elements[i]; var currentAttributes = currentElement.attributes; for (var x = 0; x < currentAttributes.length; x++) { if (currentAttributes[x].name === attrib) { foundelements.push(currentElement); } } }
It might be easier with jQuery: find element by attribute find element by attribute.
I'm not too familiar with JS, so just three generic notes:
It seems to me that the
elements[i].attributes.length > 0
check is unnecessary because the statements inside the followingfor
loop won't ifelements[i].attributes.length
is zero.Consider creating local variables for
elements[i]
andelements[i].attributes
. It would remove some duplication.for (var i = 0; i < elements.length; i++) { var currentElement = elements[i]; var currentAttributes = currentElement.attributes; for (var x = 0; x < currentAttributes.length; x++) { if (currentAttributes[x].name === attrib) { foundelements.push(currentElement); } } }
It might be easier with jQuery: find element by attribute.
I'm not too familiar with JS, so just three generic notes:
It seems to me that the
elements[i].attributes.length > 0
check is unnecessary because the statements inside the followingfor
loop won't ifelements[i].attributes.length
is zero.Consider creating local variables for
elements[i]
andelements[i].attributes
. It would remove some duplication.for (var i = 0; i < elements.length; i++) { var currentElement = elements[i]; var currentAttributes = currentElement.attributes; for (var x = 0; x < currentAttributes.length; x++) { if (currentAttributes[x].name === attrib) { foundelements.push(currentElement); } } }
It might be easier with jQuery: find element by attribute.
I'm not too familiar with JS, so just three generic notes:
It seems to me that the
elements[i].attributes.length > 0
check is unnecessary because the statements inside the followingfor
loop won't ifelements[i].attributes.length
is zero.Consider creating local variables for
elements[i]
andelements[i].attributes
. It would remove some duplication.for (var i = 0; i < elements.length; i++) { var currentElement = elements[i]; var currentAttributes = currentElement.attributes; for (var x = 0; x < currentAttributes.length; x++) { if (currentAttributes[x].name === attrib) { foundelements.push(currentElement); } } }
It might be easier with jQuery: find element by attribute.