Possible Duplicate:
Check for values in multidimensional input array
I’m using a jQuery selector to look for duplicate tokens in a set of input tags that looks like this:
<ul id="class-items">
<li>
<input type="hidden" name="tokens[0][Search_Type]" value="a" />
<input type="hidden" name="tokens[0][Search_Term]" value="123" />
</li>
<li>
<input type="hidden" name="tokens[1][Search_Type]" value="b" />
<input type="hidden" name="tokens[1][Search_Term]" value="456" />
</li>
</ul>
This is my jQuery selector check for duplicate tokens, which doesn’t seem to be working:
if ($('#class-items > li > input[name$="Search_Type"][value="' + searchType + '"] + input[name$="Search_Term"][value="' + searchTerm + '"]').length == 0)
I know that the hidden tokens are adding correctly as I can see from viewing the DOM source.
Your
nameattributes do not end withSearch_TypeandSearch_Term.They have a
]at the end, so the selector should useSearch_Type]andSearch_Term], as in: