Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot find elements with ids that have special characters like /, . #465

Closed
sainthkh opened this issue Jan 17, 2020 · 1 comment
Closed

Comments

@sainthkh
Copy link

Test Code:

<html>
<head>
<script
  src="https://code.jquery.com/jquery-3.4.1.js"
  integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
  crossorigin="anonymous"></script>
</head>
<body>
<div id="hello.world">id with dot</div>
<div id="hello/world">id with slash</div>
<div class="hello/world/2">class with slash</div>

<script>
  $('#hello.world').css('color', 'red') // cannot find an element
  console.log(document.getElementById('hello.world'))

  // $('#hello/world').css('color', 'red') // throws an error
  console.log(document.getElementById('hello/world'))

  $('.hello/world/2').css('color', 'red')
</script>
</body>
</html>

When you make an element with an id like "hello/world", Sizzle fails to find it and throws an error.

If it has '.' in the middle of a string, it cannot find an element.

These are all valid id names according to the spec.

@mgol
Copy link
Member

mgol commented Jan 17, 2020

You need to escape an ID when used in a selector via Sizzle.escape which is based on the standard CSS.escape method. See #363

@mgol mgol closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants