[Solved] How can I change id in string


Since you are already using jquery:

for (var i = 0; i < tab.length; i ++) {
  tab[i] = $(tab[i]).find("tr").first().attr("id", "id_" + i);
}

What this does:

  1. Create jquery objects from the html string: $(tab[i])
  2. Find the first tr object: .find("tr").first()
  3. Set the attribute “id” of the object to “id_” + i: .attr("id", "id_" + i)

I added “id_” because ids and classes starting with a number are invalid and may be ignored by a browser.

This will result in your array containing jquery objects instead of strings, but you can add them to your DOM just like a string. If you need the result as a string for some reason, you can just add .html() to return a html String.

0

solved How can I change id in string