JQuery selector with ids and comma

I use MyTableGrid to show an Excel control similar to my web page.

Cells refer to identifiers of type "mtgIC1_0,2" for table 1, column 0, row 2.

Unfortunately, when I try to use the jQuery selector with this id $("#mtgIC1_0,2") , it never works.

I realized that this is because of the "," because it works for any other identifiers on the page without a coma.

+6
javascript jquery
source share
4 answers

Identifier identifiers and NAME must begin with a letter ([A-Za-z]) and can be performed with any number of letters, numbers ([0-9]), hyphen ("-"), underscore ("_"), colon ( ":") and periods (".")

However, if you escape the comma, it should still work

eg

 $('#mtgIC1_0\\,2') 
+13
source share

From here http://api.jquery.com/category/selectors/

" If you wish to use any of the meta-characters (#;&,.+*~':"!^$[]()=>|/ ) as a literal part of a name, you must escape the character with two backslashes: \\. For example, if you have an an input with name="names[]", you can use the selector $("input[name=names\\[\\]]"). If you wish to use any of the meta-characters (#;&,.+*~':"!^$[]()=>|/ ) as a literal part of a name, you must escape the character with two backslashes: \\. For example, if you have an an input with name="names[]", you can use the selector $("input[name=names\\[\\]]"). "

+3
source share

I do not know if this is the reason, but according to here , identifier names should not contain commas. Relevant offer:

IDs and NAMEs must begin with a letter ([A-Za-z]), followed by any number of letters, numbers ([0-9]), hyphen ("-"), underscore ("_"), colon (":") and periods (".").

+1
source share

If you know the coordinates of the table, you can target the cell as follows:

 $('#myTable tr:nth-child(2) td:nth-child(2)').css('background-color', '#F00'); 
+1
source share

All Articles