Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape id using this jquery row on my code

Why I receive this error?

Uncaught Error: Syntax error, unrecognized expression: #15/12/2015(…)

When I execute this?

jQuery('#15/12/2015').addClass('full').removeClass('empty');

Each row contain date as id in this format id="dd/mm/yyyy"

How can i resolve it by putting id in this row?

jQuery('#' + id).addClass('full').removeClass('empty');

Thanks very much for any replies!!

M.

like image 733
Markus Werner Avatar asked Jun 11 '26 01:06

Markus Werner


1 Answers

Solution 1:

Use attribute equals selector:

jQuery('[id="15/12/2015"]').addClass('full').removeClass('empty');

you can concatenate id using:

jQuery('[id="' + id + '"]').addClass('full').removeClass('empty');

Solution 2:

convert / in id value to \\/ to create valid id selector:

id = "15/12/2015"
$('#'+id.replace(/\//g, "\\/")).addClass('full').removeClass('empty');

Working Demo

like image 101
Milind Anantwar Avatar answered Jun 15 '26 21:06

Milind Anantwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!