jQuery Syntax error, unrecognized expression: [name=Basics.Gender]
Asked Answered
S

4

12

I am upgrading from jQuery 1.4.4 to jQuery 1.7.2 and I get a syntax error. I think its due to the '.' in the Basics.Gender part of the selector.

$('[name=Basics.Gender]')

Anyone have any suggestions on how to fix this?

http://jsfiddle.net/2nBc9/

EDIT

Anyone know why the '.' breaks the selector syntax now? Are they using regex's or something in Sizzle? Or has it always been best practice to put the attribute in quotes?

Semicentennial answered 7/8, 2012 at 15:23 Comment(1)
escape the . with `\\` jsfiddle.net/2nBc9/1Chlorobenzene
K
28

Quote the value:

$('div[name="Basics.Gender"]')

http://jsfiddle.net/7Pqhc/

Kacikacie answered 7/8, 2012 at 15:26 Comment(0)
M
5

Put the attribute in quotes

$('[name="Basics.Gender"]')
Malvaceous answered 7/8, 2012 at 15:26 Comment(0)
M
4
[name='Basics.Gender']

Have you tried with quotes?

Mammy answered 7/8, 2012 at 15:26 Comment(0)
V
3

Put the attribute in quotes. The following prints "TEST" in the console:

jQuery:

$(document).ready(function() {
    console.log($("[name='Basics.Gender']").text());
});

HTML:

<div name="Basics.Gender">TEST</div>
Vav answered 7/8, 2012 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.