I have the following table and I was trying to replace the string text of each 1st col with a link. So, the text “a1” and “a2” contents would be replaced with an according-to-link “google.com/a1” and “google.com/a2” etc…(whatever) .html contents.
Solution:
We can easily achieve this by using Jquery .each()
function, When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0.
Concluson:
As we discussed in the solution Section, the .each()
method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this
refers to the element. We hope you find them helpful.