Question

I'm trying to retrieve DOM elements based on their name. Unfortunately their names have curly braces {} inside of them.

jQuery (1.6.4) is able to retrieve them without a problem. But at this point I am trying to replace these calls with getElementsByName(), but gEBN is not matching anything that has curly brackets in the query string. I have tried backslash escaping it once and twice to no avail.

Is there a way to do this without changing the convention of using the curly brackets?

It also looks like they are not in the set of characters allowed in the name attr.

Update: Seems to work in Chrome but not Safari for Windows. But what's really strange is that even Safari for Windows handles those fiddles fine.

Was it helpful?

Solution

If you read the jQuery documentation page on selectors, you'll see this:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").

OTHER TIPS

You should expect "strange" results when you do things that are explicitly outside what the standard allows. If you choose to go off the reservation, you're kinda on your own. Some browsers will work, some won't. Ones that used to work will break without warning when a new version comes out.

So it depends what you're trying to do. If you're just building something for yourself or a small team, this might be okay. If you're building something for a general audience, better to stick to the standards and not use dis-allowed characters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top