1

Is there a css parser within js?

like F("#a") will return me the element with id a.

F(".asd") will return me the elements belonging to class asd

F("p#g") will return me the p element with id g.

F("p") will return me all the p elements

etc etc

i mean i know we can probably hand-code all the rules ourselves but there got to be a better way around that right?

4
  • I think you are looking for a JS framework like jQuery - jquery.com Commented Jul 22, 2011 at 6:15
  • im looking at HOW to do it without jQuery Commented Jul 22, 2011 at 6:30
  • If those are all the rules you need, then you can write it yourself Commented Jul 22, 2011 at 6:36
  • What you are asking is a CSS selector parser, not a CSS parser. Commented Jul 22, 2011 at 7:29

3 Answers 3

8

You can use document.querySelector() and/or document.querySelectorAll(), but it doesn't have the best browser support, thanks to IE.

For better browser support, use SizzleJS, the selector engine in jQuery. It will use querySelectorAll() where supported.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, it's called jQuery.

1 Comment

im looking at HOW to do it without jQuery
0

You can use jQuery for that, buddy.

1 Comment

im looking at HOW to do it without jQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.