Skip to content Skip to sidebar Skip to footer

Jquery Pass Value Into String And Make It An Anchor

Gurus again, How to achieve this ? Queued:134<

Solution 1:

I've never tried to do this before so this could be a really awkward way of achieving this but below works. The problem you have is that the two TDs are formatted differently. The first section of my code works for the first TD and my second section of code works for the second TD.

I could combine the two sections of code to do one for the first TD and the other for the second, but I'll let you do that :)

$('.obj td').each(function(){
   fullstring = $(this).text();
   splitString = fullstring.split(',');
   splitStringLength = splitString.length/2;
   for(i=0; i<splitStringLength; i++){
      finalString = splitString[i].split(':');
      label = '<span class="label">' + finalString[0] + '</span>';
      data = '<span class="data"><a href="'+splitString[i+3]+'">'+finalString[1]+'</a></span><br/>';
      $('body').append(label + data);      
   }
});

});

Working fiddle of the above for the first TD

$('.obj td').each(function(){
       fullstring = $(this).text();
       splitString = fullstring.split(',');
       for(i=0; i<splitString.length; i=i+2){
          finalString = splitString[i].split(':');
          label = '<span class="label">' + finalString[0] + '</span>';
          data = '<span class="data"><a href="'+splitString[i+1]+'">'+finalString[1]+'</a></span><br/>';
          $('body').append(label + data);      
       }
    });
});

Working fiddle of the above for the second TD

Post a Comment for "Jquery Pass Value Into String And Make It An Anchor"