0

Can I use something like that: <select id="data[select]"> and get the value with jquery like that: $("#data[select]").val();?

1
  • 1
    You might be able to do it if you escape the []. But as already said, these characters are not valid in IDs. Apr 23, 2011 at 22:51

2 Answers 2

0

No. Why do you need to do this anyway? I'm pretty sure CSS IDs only support A-Z, 123..., and - , _.

What are you trying to accomplish by setting you ID like that? You can, however, get the element like this: $("[id='data[select]']")

3
  • @NeXXeuS: to submit values in registration page, I have to do many $("#id_name").val(); to make it. Apr 23, 2011 at 22:50
  • @NeXXeuS: Because [] are special characters for Sizzel (the selector engine). To escape them inside a JavaScript string, you need two backslashes (similar to when you want to escape special regular expression characters using a string and RegExp). Also have a look at api.jquery.com/category/selectors Apr 23, 2011 at 22:55
  • 2
    Source W3C: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
    – Paolo
    Apr 23, 2011 at 22:55
0

try this:

$('select[id="data[select]"]').val()

anyway it would be best to change the name of ID

example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.