Blog

Jquery Tip: How to wrap tags dynamically

Quick tip:

In order to wrap a <span> around an <a> tag for example:

<ul>
<li>item 1</li>
<li>item 2</li>
</ul>

to:

<ul>
<li><span>item 1</span></li>
<li><span>item 2</span></li>
</ul>

Apply this jquery call:

<script type="text/javascript">
$(document).ready(function() {
    $("li a").each(function() {
        $(this).wrap('<span/>');
    });
});
</script>

Related posts:

  1. Linking to Google’s Hosted jQuery Repository
  2. Web Design Resources: February 22nd through February 25th
  3. Freelance Web Design: Drupal Development, WordPress, SEO, jQuery, CSS: 06-27-10 – 06-28-10

Comment on this article: