Search code examples
htmluser-interaction

Is it bad practice to add interaction to elements not created for interaction?


I wasn't sure how to phrase this so the title is a bit cryptic.

I feel that elements such as <a>/<button>/etc were created for user interaction while others such as <div>/<li>/etc were created more for structure/organization. Is it bad practice to create user interaction via JS on an <li> element rather than using a button or link within the <li>?

I feel like it is bad practice, but I don't have a backing for my argument.


Solution

  • The sole reason you may want to prefer 'interactive' elements over non-interactive ones is if you plan for fallback. If you view your site on a Javascript-disabled client, links and buttons will still be clickable, and this lets you provide some fallback. <li> tags, and other "non-interactive" elements, will be as inanimate as can be, though.

    If this is not a concern, or there is no way anyways that your application can survive without Javascript, then you have no reason to worry.