I’m trying to write a jquery selector that will select objects that have the same value for two of their attributes.
Something like this:
$('div[attr1=attr2]')
Given:
<div attr1="foo" attr2="bar">A</div>
<div attr1="bar" attr2="bar">B</div>
<div attr1="foo" attr2="bar">C</div>
<div attr1="foo" attr2="foo">D</div>
I want it to return links to the B and D divs.
Any thoughts?
You can do this with custom selectors with arguments.
You define the custom selector like this:
For performance, add
[attr1][attr2]to the selector so that the native DOM filters out nodes that don’t have both attributes.