Being a front-end developer working in a team, I have found myself solving a recurring problem many times. For example, much of our frontend javascript code is written using jQuery and CSS selectors (mostly targeting a CSS "class"). The problem is, is that many times another developer that is fixing some CSS code will remove a class or will change the DOM element nesting it under another element making the JS code break.
To prevent this, my idea was to use/add a "data-js" attribute to each element that we want to use for Javascript. However I am not sure about the performance of a jQuery selector written like this:
$('[data-js="my_js_selector"]').click();
Another idea I had, was to add a js-specific class to a dom element that is somehow manipulated by Javascript:
<a href="lol.com" class="js-link">link</a>
and then calling it simply with $('.js-link').click()
It would be very nice that you could only look into HTML and tell that some element has some Javascript manipulations attached without actually looking into the JS code.
Is this a good idea? Or are there some other best practices to separate JS-triggering from CSS styling?