G
G
GLaskov2013-11-23 13:36:43
css
GLaskov, 2013-11-23 13:36:43

How to create a small CSS parser in JS?

Here is the problem: there is a CSS code, for example

a {
color: red;
}
b {
background: green;
}

How using JS and regular expressions is it possible to break the code into blocks and put them in an array like this:
array[0] = ['a', 'color: red;' ];
array[1] = ['b', 'background: green;' ];
I’m not strong in regular expressions, therefore I’m not sure that this should be done with their help, please tell me the solution to the problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jonh Doe, 2013-11-23
@CodeByZen

And if you go through the DOM and make an array with all the elements and their styles. For example in jQuery it's quite easy.

H
Hazrat Hajikerimov, 2013-11-25
@hazratgs

Today it was on Habré
php css parser
http://idc.anavallasuiza.com/project/stylecow/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question