Hello everyone,
While developing a design using jQuery I stumbled across a problem. How would I know, without having to look through the javascript, if jQuery isn't doing a selector on a class in my HTML? That is to say, if I wanted to change the class to something else, I have no way of knowing if that class is being used elsewhere so it makes it difficult for me to easily update the design.
So, my thought was to duplicate a class name and append text (say, "-jquery") to the end of it if it is being utilized. This way, if I wanted to change the design in the future I could do so freely, and I would instantly know what elements on the page are being used in my javascript.
For example, let's say I have a simple div with a class:
<div class="header">This is a test</div>
And javascript that does something to the div:
$(".header").click(function() {
$(this).slideUp();
});
My idea is to change it to this:
<div class="header header-jquery">This is a test</div>
$(".header-jquery").click(function() {
$(this).slideUp();
});
Thereby separating my CSS and jQuery classes, making it easier to identify elements being used by jQuery, and allowing me to update the class if need be without affecting my javascript. Sure, the code looks a bit messier, but I don't mind.
The questions:
- Is this a common practice at all?
- Should I do this?
- Is there a better way of achieving what I want?
EDIT:
One last question:
- Is there, perhaps, a plugin for Visual Studio that may do this for me? That is, if it notices me editing the class of an element that is being used in jQuery, it would warn me? Or perhaps even color-codes the class name to let me know it's being used. A feature like this in the IDE would be killer...
Bara