Sorry, I specified my problem incorrectly. Apologies.

I meant to ask 'how do you wrap the text in an element in an anchor,
if that's the only node within that element'.

This was my solution, although it's very long and unwieldy:

function wrapTextInAnAnchor(theElement){
        $(theElement).each(function(){
                var theAnchor = document.createElement("a");
                theAnchor.setAttribute("href","#");
                theAnchor.setAttribute("class","handle");
                var theText = $(this).text();
                var newText = document.createTextNode(theText);
                theAnchor.appendChild(newText);
                $(this).text("");
                this.appendChild(theAnchor);
        });
}

I was using 'this' in place of $(this), which was fine in firefox, but
IE didn't seem to know what 'this' was. That's another issue, I
suppose...

Thanks for looking into it, Karl.

On 3/22/07, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> Dan Eastwell schrieb:
> > How can I change this:
> >
> > <h2>text</h2>
> > <h2>other text</h2>
> >
> > to this:
> >
> > <h2><a href="#">text</a></h2>
> > <h3><a href="#">other text</a></h3>
> >
> > Thanks,
> >
> > Dan.
>
>
> Try (untested):
>
> $('h2+h2').each(function() {
>      var $$ = $(this);
>      $$.before('<h3><a href="#">' + $$.text() + '</a></h3>').remove();
> });
>
>
> -- Klaus
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>


-- 
Daniel Eastwell

Portfolio and articles:
http://www.thoughtballoon.co.uk

Blog:
http://www.thoughtballoon.co.uk/blog

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to