I'm in a bit of a pickle with my codebase and was considering using HTML comments to store a chunk of HTML code that I need to duplicate. I know there are more proper methods to handle this, like using data attributes or JavaScript variables, but honestly, implementing them would require a ton of work given the state of the code. It's outdated and messy, and I want to drop a quick fix rather than refactor everything right now.
Here's the plan: inside a form, I'd have a comment where my template form fields would be placed. Then, when a button is clicked, some jQuery will grab that comment's HTML and append it to a div where the fields will show up. But I'm aware this might raise a few eyebrows, not to mention possibly leading to issues. So, I'm looking for feedback on the potential problems I might encounter with this workaround and if there are any better short-term solutions available without diving deep into a refactor.
1 Answer
You should definitely check out the HTML element. It's designed for exactly this purpose. It lets you define HTML that isn't displayed on the page unless you tell it to. This way, you can easily duplicate your form elements without hacking it together with comments. It's a game changer!
TIL! The tag seems perfect for what I need, especially since I can inject it similarly to an HTML comment. I'll experiment with it. Thanks!