views:

294

answers:

2

Do I need to somehow escape a space when using jquery to select with contains/find?

I am mocking this up so pardon the typos... If I have a SELECT tag that has some options

<select title="animals">
<option value="Dog Black">Dog Black</option>
<option value="Cat Black">Cat Black</option>
<option value="Dog Brown">Dog Brown</option>
</select>

I am trying to find the options in this select using jquery. but it appears that the "find" method or "contains" function fails when the value being passed to search for contains a space. For example:

The following returns a size of 2:

$('*[title="animals"]').find("option:contains('Dog')").size()

But this returns 0 whre I would expect 2 as well:

$('*[title="animals"]').find("option:contains('Dog B')").size()

My guess is that this has something to do with the selector and it is looking for a child element with "B" or something but Im not really sure.

A: 

Sorry after banging my head for hours I found a a bug elsewhere in the code after posting this that caused the issue, closing this out

Jay
A: 

I tested this exact code in a page with essentially nothing else in it, and it returns 2 on both find() functions in all of my browsers. Perhaps there is something else in your code interfering with your results? Maybe you're stashing the results somewhere and losing track of the value, or overwriting it?

Or maybe you already figured out the problem. :p

Frank DeRosa
Thanks for testing It was a bug in the 1.2.6 version of jquery. 1.3.2 works fine. Ill give you the credit for helping :)
Jay