Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting table cells data to internal links in a separate .js file

Having an issue with a small project and I've been stuck for the past 3 days... I have to convert data cells on a left column of a table in a html file into links (that will target other html files) using javascript & jquery in a separate js file. I am not able to edit the html file due to restrictions on the question.

like image 595
eddyiction Avatar asked Jan 23 '26 19:01

eddyiction


1 Answers

I hope I understood your question correctly. You could access the cells with the selector .code and then use append() to put a link in there like so:

$(".code").each(function(i){ //find the right cells and for each one...
    var text = $(this).text(); //...read the contents...
    text = text.substring(3); //...remove the first 3 letters...
    $(this).text(""); //...remove the text...
    $(this).append("<a href='"+text+".html'>"+text+"</a>"); //...and replace with a link
});

Example: http://jsfiddle.net/7fawbkck/2/

like image 175
icke Avatar answered Jan 26 '26 09:01

icke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!