1

I have a table with a series of rows. I want to change them into divs, but maintain (somehow) their positional information. At the moment, this is what I'm doing:

$("./tr[1]") {
  add_class("mw_old_row_1")
}
$("./tr[2]") {
  add_class("mw_old_row_2")
}
$("./tr") {
  name("div")
}

But this isn't ideal because:

  1. It's super-repetitive
  2. I don't know how many rows there are

Is there a way to take the child number and include that in the class I'm assigning?

gregorygtseng
  • 851
  • 4
  • 12

1 Answers1

2

Yup, you want to make use of the index() function. Below is the example you wrote reworked using index():

$("./tr") {
  add_class("mw_old_row_" + index())
  name("div")
}

Below is a link with the following example in tritium tester: http://tester.tritium.io/775895b154e8e2ce99e100967299c10d73dbeb91

noj
  • 2,542
  • 1
  • 14
  • 9