wrap() and innerWrap() are available for adding html around elements but
this little plugin wraps html around text nodes:

For example:
 jQuery code: $("LI INPUT").wrapText("<LABEL/>")
 Before: "<li><input/>some text</li>"
 After:   "<li><input/><label>some text</label></li>"

Note: This ignores empty text nodes or those containing just white space.
Also ignores text in any child elements.

I hope it is useful for some of you!
Cheers,
George

(Tested in IE6, FF2.0.0.1, Opera9.10)

// Plugin to wrap html around all non-empty text nodes within an element:
(ignores text in child elements)
// By George Adamson, SoftwareUnity.com, March 2007.
jQuery.fn.wrapText = function(html){
  return this.each(function(){

        $(this.childNodes).filter("[EMAIL PROTECTED]").each(function(){
                if($.trim(this.nodeValue).length > 0)
                        $(this).wrap(html)
        })

  });
};

-- 
View this message in context: 
http://www.nabble.com/wrapText-plugin-%28to-wrap-html-around-text-nodes%29-tf3363574.html#a9357658
Sent from the JQuery mailing list archive at Nabble.com.


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

Reply via email to