Skip to content

Instantly share code, notes, and snippets.

@KruegerDesigns
Created February 1, 2012 22:50
Show Gist options
  • Save KruegerDesigns/1719961 to your computer and use it in GitHub Desktop.
Save KruegerDesigns/1719961 to your computer and use it in GitHub Desktop.
Wrap contents of a tag in a span, or other tag.
// Used to style ol li items when applied by a WYSIWYG editor.
$("#content ol li").each(function(){
$(this).contents().wrap("<span>");
});
@KruegerDesigns
Copy link
Author

If you need help visualizing the usefulness of this, here's a screen shot: http://d.pr/8QjU

I needed this script when I was developing styles for a CMS Website. The editor the client would use has options for adding styles, and you could carefully instruct the WYSIWYG editor to create a div in each list item, or "li", but... that's just unrealistic to expect a client to figure out and get right.

With this JS you can create the styles and whenever the client adds an ordered list, or "ol", everything just works.

-Adam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment