Is there any way to access HTML elements with IDs including symbols such as slashes as shown below?

console.log ($("# point-abc \/company"));

Uncaught Error: Syntax error, unrecognized expression

  • Answer # 1

    console.log ($("# point-abc \\\/company"));

  • Answer # 2

    It's strange to write "slash" and if you need to escape "backslash"
    It will be a good way of writing


    "\" Becomes "\\" for string notation, and it escapes it, so it is "\\\\"
    In addition, "/" becomes "\ /", so escape and "\\ /" need 6 "\" results
    Use escape function

    console.log ($("#" + CSS.escape ("point-abc \\/company")). length);

Related articles