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?

superlogical
  • 14,332
  • 9
  • 66
  • 76

4 Answers4

28

Quote the value:

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

http://jsfiddle.net/7Pqhc/

Esailija
  • 138,174
  • 23
  • 272
  • 326
5

Put the attribute in quotes

$('[name="Basics.Gender"]')
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
4
[name='Basics.Gender']

Have you tried with quotes?

JNDPNT
  • 7,445
  • 2
  • 34
  • 40
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>
jeff
  • 8,300
  • 2
  • 31
  • 43