jquery -div id match failing due to presence of \ in the id

55 Views Asked by At
$('#bannerAbc tr td .scroller div.checkbox[id="' + $('#hdnfieldstring').val().trim().split(',')[i] + '"]').each(function () {
    $(this)[0].className = $(this)[0].className + " checked";
})

hdnfieldstring has values like 'abc\xyz, edc\qaz' each of the value being div id. The above code works for id without \ in them, but does not work of the sample data i provided above. Can you please help

1

There are 1 best solutions below

2
On BEST ANSWER

Backslash has to be escaped, so change one backslash to two backslashes.

$('#bannerAbc tr td .scroller div.checkbox[id="' + $('#hdnfieldstring').val().trim().split(',')[i].replace('\\', '\\\\') + '"]').each(function () {