I have a webpage that has a comment box that can be toggled by clicking a link (the opening and closing of the box is controlled using JavaScript, specifically JQuery). This box is hidden by default, so naturally, it's impossible to display without the use of JavaScript. I'm not concerned by this fact: the comment box is not a "necessary" feature and this is a small personal site, so I don't mind that a tiny percentage of visitors may not experience full functionality. However, I would like to display a warning if the user does not have JavaScript enabled.
I've considered the idea of doing this by presenting a small message (with the use of a simple HTML <p>
tag) near the link that toggles the comment box, using the following bit of code:
<p class="alert" id="nojs-warning">You must have JavaScript enabled to leave a comment.</p>
Of course, I don't want to display this if JavaScript is enabled, so I have the following JQuery trigger set up to immediately hide the box when the page is loaded:
$(function() {
$('#nojs-warning').hide();
});
Thus, if the user has JavaScript enabled, the event will fire and the warning will be hidden; if the user doesn't have JavaScript enabled, the event won't fire, and thus the warning will still be displayed.
For such a small, personal site, this seems like an elegant solution. Are there any pitfalls to this approach?