Get content from next <td> and turn it into a href

Hi I have table with which is pre populated. Column 2 contains some text, and Column 3 contains html for a href. I want to wrap the text in column 2 with the href from Column 3. Problem is each row contains different values in each td. I have come up with the below code but can’t get it to work. any ideas? Cheers

$j( "td.column-2" ).wrap( "<a href = '#'></a>" );
var link = $j('td.column-2').next().attr("href");
$j( "td.column-3" ).prev().attr( "href",link);

The following should work, but if it doesn’t paste the HTML for the table

/**
 * Loops through each .column-3 and wraps it's sibling, .column-2, with a link
 */
$j('td.column-3').each(function(){
	var $this = $(this)
	var link = $this.text() 	//Assuming this column only contains text
	if(link)
		$this.prev('.column-2').wrapInner("<a href='link'></a>")
})

Thanks Labofoz

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.