Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

sizzle

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?

like image 239
superlogical Avatar asked Aug 07 '12 15:08

superlogical


4 Answers

Quote the value:

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

http://jsfiddle.net/7Pqhc/

like image 121
Esailija Avatar answered Nov 05 '22 14:11

Esailija


Put the attribute in quotes

$('[name="Basics.Gender"]')
like image 23
Rocket Hazmat Avatar answered Nov 05 '22 15:11

Rocket Hazmat


[name='Basics.Gender']

Have you tried with quotes?

like image 4
JNDPNT Avatar answered Nov 05 '22 15:11

JNDPNT


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>
like image 3
jeff Avatar answered Nov 05 '22 13:11

jeff