3

I have html snippets and i was wondering where I should keep them... For example:

Currently I have the following in my HTML page

<div id="Mailbox" class="ui-corner-all">
    <div id="Messages">
        <ul class="messageList">
            <li class="noMessage">You have no messages</li>
        </ul>
    </div>
    <div class="trashIcon ui-corner-bottom">
        Delete Selected Message(s)
    </div>
</div>

Then, when the page loads, jquery and javascript turns this into a full functioning mailbox system.

What I am wondering is - Should I bother with the HTML snippet, or just build the entire thing through JS?

2 Answers 2

4

Having the markup in your page potentially degrades much better for users with no script. Plus, it's usually easier to work with existing markup than build it completely from scratch with JavaScript.

Sometimes templating can be an appropriate solution. This will not degrade for users without script, but if you have a script-heavy page that needs to create a lot of markup dynamically, templates can make this simpler.

If you find that you are duplicating blocks of markup from page to page, this should probably be addressed server-side by storing the common content in a single location.

Sign up to request clarification or add additional context in comments.

Comments

0

Depends if you're writing an application or a website. Does SEO matter? Does accessibility matter? Do you need to support a wide range of browsers and devices?

If not then I'd write it in JS but take a look at some MVC frameworks such as backbone.js or JavaScriptMVC etc. in which case you'll likely want to be using client-side templating so you're html should be in the page but not in the DOM.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.