madrobby / zepto

Zepto.js is a minimalist JavaScript library for modern browsers, with a jQuery-compatible API
http://zeptojs.com
Other
15k stars 3.93k forks source link

select ID start with number is not a valid selector #1333

Closed ewwink closed 5 years ago

ewwink commented 6 years ago
<div id="123id">
  <p>hello</p>
</div>
<script>
var aa = $('#123id p').html();
console.log(aa);
</script>

SyntaxError: '#123id p' is not a valid selector but jQuery is fine.

fangbinwei commented 6 years ago

zepto use document.querySelectorAll('#123id p') to select the element node, and querySelectorAll needs valid CSS selectors.

However, it seems that ID selectors are not allowed to start with a number. <style> #123id {background-color: red; }</style> doesn't work either.

https://css-tricks.com/ids-cannot-start-with-a-number/

I hope it can help you.

shirenhu commented 5 years ago

but you can use document.getElementById to select the element

madrobby commented 5 years ago

Please fix your IDs to conform to the HTML standard.