I am trying to select a jQuery filtered object with an attribute value, which is a unique file name. I cannot escape from slashes when the selector is done with var. I lost 2 hours trying to use several combinations, but I think I have something missing. Thanks in advance for the light.
My HTML:
<table class="table table-condensed" id="CLKPMTable_2"><tbody><tr class="click-row" valuetype="PM" filename="\\server\folder\file1" paymentmethodid="1"><td class="col-md-1"><img width="24" height="24" src="/Content/img/123.png" id="PMURLIMG_"></td><td class="col-md-10" id="PM_FILENAME_">BO OCT</td><td class="col-md-1 text-right"><img width="16" height="16" src="/Content/img/notyet.png" id="PM_STATUS_"></td></tr><tr class="click-row" valuetype="PM" filename="\\server\folder\file2" paymentmethodid="2"><td class="col-md-1"><img width="24" height="24" src="/Content/img/visa.png" id="PMURLIMG_"></td><td class="col-md-10" id="PM_FILENAME_">O SEP</td><td class="col-md-1 text-right"><img width="16" height="16" src="/Content/img/notyet.png" id="PM_STATUS_"></td></tr></tbody></table>
My Javascript:
var filename = "\\server\folder\file1"; var selec = $('tr[valueType="PM"][filename="'+filename+'"]'); alert(selec.attr("paymentmethodid"));
Doesn't work with:
var filenamescaped = filename.replace('\\','\\\\') var selec = $('tr[valueType="PM"][filename="'+filenamescaped+'"]');
Also didn't work with either (from: jQuery's official doc to avoid the characters used in css ):
function jq( myid ) { return myid.replace( /(:|\.|\[|\]|,|=)/g, "\\$1" ); } var filename = "\\server\folder\file1"; var filenamescaped = jq(filename);
My violinist to do some tests: jsfiddler
source share