i have dom element contains qualified name part of id attribute;
<div id="domain\element\div">my div</div>
it seems impossible jquery select element id. here's experiment;
var $e1 = $('#domain\\\element\\\div'); var $e2 = $('#domain\\element\\div'); var $e3 = $(document.getelementbyid('domain\\\element\\\div')); console.log($e1); console.log($e2); console.log($e3);
the output of console displays first 2 empty while third works;
[] [] <div id="domain\element\div">todo write content</div>
i using jquery 1.5.2. bug jquery or selector strings wrong?
if can change id within html code, find other separator backslash \
id can make valid id selector (see here). underscore _
good.
if can't alter html, jquery can still work backslashes in ids , id selectors. except, you'll need use 4 backslashes match each literal backslash in id selector:
$('#domain\\\\element\\\\div')
you achieve by
taking id:
domain\element\div
adding
#
symbol , escaping backslashes selector:#domain\\element\\div
escaping each pair of backslashes use in javascript strings doubling them (also notice quotes):
'#domain\\\\element\\\\div'
then passing string
$()
above.
Comments
Post a Comment