I am using MyTableGrid to show an Excel like control in my webpage.
The cells are referenced with ids like "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 figured it is because of the "," since it works for any other ids in the page without coma.
In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.
The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
Approach: Select the ID's of different element and then use each() method to apply the CSS property on all selected ID's element. Then use css() method to set the background color to pink to all selected elements. Display the text which indicates the multiple ID selectors.
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 (".")
However if you escape the comma it should still work
e.g
$('#mtgIC1_0\\,2')
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With