-3

If I have an id:

#my~~id

Q#1: Is there a way to target it using js/jQuery? Ex:

var myid = $('#my' + ~~ +'id')

Update: The 'duplicate' doesn't address my question about replace as this question isn't about spaces in a id.

parti
  • 205
  • 3
  • 15

2 Answers2

1

first they need to be string and you need to escape them with \\ as per escaping instructions in jQuery selectors api

$('#my\\~\\~' +variable)
charlietfl
  • 170,828
  • 13
  • 121
  • 150
0

In $ or querySelector tilde has a special meaning and won't be interpreted as part of the ID. But document.getElementById('my~~id') would allow you to be more specific. Better yet: change to a different ID, this one is hard to work with.

Ben West
  • 4,398
  • 1
  • 16
  • 16