I want to detect all links for all td with item-description class; How to make this work if my string is both just the link and when the description is link with other text. Here is my code but it does not work!
<script>
var items = document.getElementsByClassName("item-description");
for (var i = 0; i < items.length; i++) {
var text = items[i].innerText;
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
text.replace(exp, "<a href='$1' target='_blank'>$1</a>");
}
</script>
It doesn't work as it is, the text in are generated from form submissions. Basically if the text of td is something.com I want to make that into an a tag inside the td. I also want it to work when the text is the link text with other text. Sample: https:something.com other text here
First of all a TD is a cell in a table.
The cell can have different elements in it, including the tag which can make it clickable.
However, due to the nature of a table-cell, the height and width of a cell does not depend only on its contents but also on its neighboring tags which can cause the clickable area to cover only a part of the cell.
Hence to make the entire link clickable, you will have to bind a JavaScript (JS) click event on that td to make it to redirect to another page or whatever link you want.