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 questionAnybody 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.
精彩评论