Creating HTML in jquery is a tedious and, quite frankly, boring task. Coming from a Rails web development background, I always wanted a way to create HTML like Rails does, with a content_tag method helper that can take attributes as has and be passed function blocks to quickly generate HTML within ruby. This is where the inpsiration for EasyHTMLTags comes from.

Let’s just dive in.

This plugin isnt anything complicated, just useful, so let’s see how it works.

1. Download the plugin and install into the appropriate directory.

2. Link to the plugin from your HTML

<script src="/path/to/javascripts/jquery.easy_html.js" type="text/javascript" charset="utf-8"></script>

3. Start creating tags

# =>  "<li></li>"

$.tag("li", "some content")
# =>  "<li>some content</li>"

$.tag("li", "some content", { class: "my_class", id: "special_id"})
# =>  "<li class="my_class" id="special_id">some content</li>"

$.tag("li", "some content", { class: "my_class", id: "special_id"}, function() { return $.tag("span", "some extra stuff")})
# =>  "<li class="my_class" id="special_id">some content<span>some extra stuff</span></li>"

That’s it. Hope you find it useful.

Check out the docs for more information.