1

I am using following jquery selector by id

$("#rs_0.01").val();

So my small question is: this valid or not ? As it's not working in my case.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
Kapil Verma
  • 178
  • 3
  • 17
  • `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 (".").` according to [this](http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html) – guradio Jul 12 '16 at 07:22
  • `$("[id='rs_0.01']").val();` or `$("#rs_0\\.01").val();` – Pranav C Balan Jul 12 '16 at 07:23
  • 1
    $("[id='rs_0.01']").val(); is good for me. @PranavCBalan Please post it as answer. Other solutions may work. But i am using loop for displaying currency denominations my loop contains 1,2,5,10,etc values. So mentioned solution is working for me. – Kapil Verma Jul 12 '16 at 08:01

3 Answers3

4

Check documentation of jQuery Selectors

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"). The W3C CSS specification contains the complete set of rules regarding valid CSS selectors. Also useful is the blog entry by Mathias Bynens on CSS character escape sequences for identifiers.


So you can use
$("#rs_0\\.01").val();

or use attribute equals selector instead

$("[id='rs_0.01']").val();
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
0

Use: You need to escape special chars:

$("#rs_0\\.01").val();
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27
0

In your case you got few ways to retrieve value of a textbox by using id selector with the same name which you have specified in the question..

One way is by doing like this:

$("[id='rs_0.01']").val();

or you can use the escape sequence inbetween the selector name like this:

$("#rs_0\\.01").val();
Lokesh_Ram
  • 391
  • 4
  • 10