0

I am embarking on a daunting task of cleaning up an existing site. I'm completely stripping out years worth of CSS added by multiple developers in favour of adding a new framework and my own set of clear CSS styles.

What I want to do is reserve ID for JS and class for CSS. I do know that some of the JS will need to look at classes but that's ok. There are however many times I will be able to change the class name to an ID without issue.

The existing site has 11755 instances of class=" across 457 files but I can't just strip them out because I know that some JS is dependant on some of those classes.

Can anyone provide any help as to how to locate the dependant classes in the JS? I have no idea how to do this other than manually and that seems crazy.

3
  • Is the JS using selectors? As in, .class strings? Commented Feb 7, 2013 at 13:02
  • but if a javascript function can be applied to more than one element of the same class, you will want to keep it and not create a function for every id Commented Feb 7, 2013 at 13:07
  • Yes Florian the JS is mostly jQuery using .class. I will not be removing all the classes w3jimmy, I just need to know which ones are safe to remove and I will then go through the JS and only change to IDs if it makes sense. I also forgot to mention I use Sublime Text 2 Commented Feb 7, 2013 at 14:56

2 Answers 2

1

Search all of your files with the following regex (you have to figure out how on the system you're using)

class=("[^"]*")

with will get all your class names within quotation marks.

You intersect this list with the strings (in quote marks) used in the javascript. The intersection will be the classnames that the javascript is dependent on.

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

Comments

1

Start by finding in files for $(' or $(" or getElementById

A good regular expression will start you up with substancial material to work on.

Comments

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.