[openstreetmap/openstreetmap-website] Prefix html class names with js- when used by JavaScript? (Issue #3801)

Tobias notifications at github.com
Fri Nov 18 15:53:18 UTC 2022


> I think that we should follow the convention to prefix all the classes used in our Javascript with js-. (…)
> I'd like to hear any feedback from other developers who think this is either a good or bad idea, before I implement it.

I agree that separating the names based on usage is a very good idea. 

In my last company, we had the rule to not query classes (or IDs) at all, but **use data attributes** instead. It would be `<div class="spinner" data-capability="spinner" />` with a lookup that also handled cases where multiple capabilities where attached (something like `data-capability~=spinner` I think).

The advantage is, that this splits the two works (style, javascript) even more.
However, IMO the advantage over `js-spinner` is mor stylistic.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/3801#issuecomment-1320208293
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/3801/1320208293 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20221118/af4a3a20/attachment.htm>


More information about the rails-dev mailing list