You can use square brackets, you just have to put a '\' before them
(which has to be done as '\\' because of JavaScript's encoding)

http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_element_that_has_weird_characters_in_its_ID.3F

Karl

On Feb 8, 2008 1:28 AM, Dave Stewart <[EMAIL PROTECTED]> wrote:
>
> I'm finding it impossible using jQuery to select any attributes with
> square brackets in them.
>
> I'm sure most people know PHP uses square brackets within form element
> names to submit multi-dimensional arrays, ie:
>
>         contact[name]
>         contact[email]
>         contact[telephone]
>         contact[options][option 1]
>         contact[options][option 2]
>         contact[options][option 3]
>
>
> This is read natively by PHP as:
>
>         contact => array (
>                 name,
>                 email,
>                 telephone,
>                 options => array(
>                         option 1,
>                         option 2,
>                         option 3
>                         )
>                 )
>
>
> In a way, jQuery's refusal to recognise square brackets makes sense,
> as it leans towards attribute selectors (which are fantastic tools),
> but vanilla getDocuementById() works, so I'm wondering why jQuery
> hasn't some kind of check for this kind of thing?
>
> In the meantime, does anyone have any "best-practice" workarounds to
> this issue, for example for the above data structure?
>
> Combined selectors, e.g.
>
>         #contact-email
>
> and separate selectors e.g.
>
>         #contact #email
>
> offer different advantages. Has anyone any preferences, and why??
>
> Many thanks,
> Dave Stewart
>

Reply via email to