I've needed this myself and have seen this come up on the list a few times.
Although, the jQuery core makes this pretty easy to accomplish ... it should
involve less typing and be more explicit. I've gone ahead and created a
proper jQuery.fn.innerWrap method. It works much the same way wrap does ...
just does it on the inside instead of outside. :)

You can find the source and example here:
http://brandonaaron.net/jquery/snippets/innerWrap/

--
Brandon Aaron

On 6/1/07, WPWOW <[EMAIL PROTECTED]> wrote:


i want to turn
<a href="#">test</a>
into
<a href="#"><span>test</span></a>

so...

$("a").prepend("<span>").append("</span>");

doesnt work because of the open tag. the first span is closed and the
second span is thrown away. (this quality should be noted in the docs,
i think.)

$("a").wrap()

would apply content to the outside of the link

$("a").html().wrap(..)

html() breaks chaining

which leaves us with

$('a').each(function(){ $(this).html('<span>'+ $(this).html() +'</
span>') });

surely there is a less ugly way, or no?

if not, i would like to propose something along the lines of
innerWrap(). same as wrap() but applies content to inside of element.


Reply via email to