[jQuery] Re: Wrapping non empty text node with span

2009-01-16 Thread Beres Botond

I don't think you need .find(li), just

$(#target  li).each(function(){

Other than that, looks pretty simple already


On Jan 16, 10:50 am, Jacky jacky...@gmail.com wrote:
 Hi all,

 I'm looking for a way to wrap text node with span.

 HTML:

 ul id=target
 liItem 1/li
 liItem 5
   ul
 liItem 5-1/li
 liItem 5-2/li
 liItem 5-3
   ul
 liItem 5-3-1/li
   /ul
 /li
   /ul
 /li
 liItem 6/li
   /ul

 Expected Outcome:
 ul id=target
 lispanItem 1/span/li
 lispanItem 5/span
   ul
 lispanItem 5-1/span/li
 lispanItem 5-2/span/li
 lispanItem 5-3/span
   ul
 lispanItem 5-3-1/span/li
   /ul
 /li
   /ul
 /li
 lispanItem 6/span/li
   /ul

 Currently I do it by:

 $(#target  li).find(li).each(function(){
 if(this.childNodes[0]  this.childNodes[0].nodeType == 3){
 var data = $.trim(this.childNodes[0].data);
 if(data){
 this.childNodes[0].data = data;
 $(this.childNodes[0]).wrap(span/span);
 }
 }

 });

 I wonder if there is any simpler way to do this?
 --
 Best Regards,
 Jacky
 網絡暴民http://jacky.seezone.net


[jQuery] Re: Wrapping non empty text node with span

2009-01-16 Thread Beres Botond

Actually, you'll need

$(#target).find(li).each(function(){

to process each li from target ul.

On Jan 16, 12:22 pm, Beres Botond boton...@gmail.com wrote:
 I don't think you need .find(li), just

 $(#target  li).each(function(){

 Other than that, looks pretty simple already

 On Jan 16, 10:50 am, Jacky jacky...@gmail.com wrote:



  Hi all,

  I'm looking for a way to wrap text node with span.

  HTML:

  ul id=target
  liItem 1/li
  liItem 5
ul
  liItem 5-1/li
  liItem 5-2/li
  liItem 5-3
ul
  liItem 5-3-1/li
/ul
  /li
/ul
  /li
  liItem 6/li
/ul

  Expected Outcome:
  ul id=target
  lispanItem 1/span/li
  lispanItem 5/span
ul
  lispanItem 5-1/span/li
  lispanItem 5-2/span/li
  lispanItem 5-3/span
ul
  lispanItem 5-3-1/span/li
/ul
  /li
/ul
  /li
  lispanItem 6/span/li
/ul

  Currently I do it by:

  $(#target  li).find(li).each(function(){
  if(this.childNodes[0]  this.childNodes[0].nodeType == 3){
  var data = $.trim(this.childNodes[0].data);
  if(data){
  this.childNodes[0].data = data;
  $(this.childNodes[0]).wrap(span/span);
  }
  }

  });

  I wonder if there is any simpler way to do this?
  --
  Best Regards,
  Jacky
  網絡暴民http://jacky.seezone.net