Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Id name with backwards slash returns null

I have an HTML tag with the name foo\bar and when trying to get the selector by id name it returns null:

<html>
<body>
<div id="foo\bar">a</div>
<script>
var esc = document.querySelector('#foo\\bar'); 

console.log(esc); //returns 'null'
</script>
</body>
</html>

Not sure why this happens, when logging #foo\\bar to the console it perfectly outputs the correct id of the tag:

console.log("#foo\\bar");

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var esc = document.getElementById('foo\\bar'); 

Use getElementById instead of querySelector.

<html>
<body>
<div id="foo\bar">a</div>
<script>
var esc = document.getElementById('foo\\bar'); 

console.log(esc); //returns '<div id="foo\\bar">a</div>'
</script>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!