开发者

Is there an existing CSS3 selector parser for JavaScript? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite 开发者_JS百科off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 9 years ago.

Improve this question

Anybody know of snippet that will parse a CSS3 selector like this:

"form#network_template[method='put'][action='#form_{keyname}']"

to this:

{
  tag: "form",
  id: "network_template",
  method: "put",
  action: "#form_{keyname}"
}

or this:

<form id="network_template" method="put" action="#form_{keyname}">


Assuming you meant to ask for a CSS3 selector parser in the title, Slick, used in Mootools, may do the job; from the github page:

Slick.parse("h1, h2, ul > li, .things")

{
"raw": "h1, h2, ul > li, .things",
"expressions": [
    [{ "combinator":" ", "tag": "h1" }],
    [{ "combinator":" ", "tag": "h2" }],
    [{ "combinator":" ", "tag": "ul" }, { "combinator": ">", "tag": "li" }],
    [{ "combinator":" ", "tag": "*", "classList": ["things"], "classes": [{"value": "things", "regexp":RegExp }] }]
]
}

Mootools can also create an element with appropriate attributes straight from a selector.


Sizzle is used underneath jQuery. And there is also Peppy. Newer versions have at least some CSS3 selector support. YMMV.

Google searches reveal interesting leads.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜