What chars needs escaping in querySelector?

前端 未结 2 612
长发绾君心
长发绾君心 2020-12-11 01:29

According to the document here: https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector#Notes

It says some characters need to be escaped when doing q

2条回答
  •  臣服心动
    2020-12-11 01:51

    If it is possible, you can use this solution, albeit not cross-browser (all modern browsers except IE) - https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape

    CSS.escape(".foo#bar") ->"\.foo\#bar"
    

提交回复
热议问题