javascript - document.querySelector get class name containing parentheses - Stack Overflow

I am writing software that has to work with the dom of a third-party web-app that I don't control.

I am writing software that has to work with the dom of a third-party web-app that I don't control. Some of the class names have parameter, eg class="view_box(200px)". I'm guessing these class names are Sass/Less mixins/arguments?

document.querySelector doesn't seem to like .view_box(200px) as a valid class selector, and simply querying .view_box doesn't return any of the elements that have the full string with argument as their class.

I tried escaping the parens as \( and \). I even tried URL encoding them as %28 and %29. I get the error Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '.view_box(200px)' is not a valid selector.

I am writing software that has to work with the dom of a third-party web-app that I don't control. Some of the class names have parameter, eg class="view_box(200px)". I'm guessing these class names are Sass/Less mixins/arguments?

document.querySelector doesn't seem to like .view_box(200px) as a valid class selector, and simply querying .view_box doesn't return any of the elements that have the full string with argument as their class.

I tried escaping the parens as \( and \). I even tried URL encoding them as %28 and %29. I get the error Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '.view_box(200px)' is not a valid selector.

Share Improve this question asked Dec 22, 2018 at 6:58 V. RubinettiV. Rubinetti 1,77520 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

You need to pass a literal backslash into the argument:

document.querySelector(".view_box\\(200px\\)")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742330960a4423710.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信