Target escaped div string
Trying to target a div that may have some special characters in it & then change it's srcset.
Everything is coming in correctly, so it's just the targeting part that I need help with.
I broke it down into parts to be able to concatenate & then target it:
- var smdiv = 'mydiv_rowset_'+rowset+'_'+mydata[rowset].fieldNames[k];
- var smesc = smdiv.replace(/[!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, "\\\\$&");
- var smimgsrc = ' source\\\\.img2xsm';
- var small = '\\\\#'+smesc+smimgsrc;
- console.log('SmImg-small: ' + small); // Ex. \\#mydiv_rowset_mytable31_field8\\@2x source\\.img2xsm
- $(small).attr('srcset', 'some new value'); // Throws syntax error, unrecognized expression on what's placed in for 'small'
Basic html:
- <span id="mydiv_rowset_mytable31_field8@2x" class="myclass">
- <picture>
- <source class="img2xsm" srcset="~~">
- </picture>
- </span>
I've tried $('small') and $('"'+small+'"')... still doesn't work. What am I missing as the target is now an escaped string?