8

I'm trying to update the value attribute of a button inside a table cell.

I'm iteration over each cell and my code looks like this:

for (var i = 0, cell; cell = table.cells[i]; i++) {                            
    $(cell).find('.btn btn-default').val("new value");                  
}

But this doesn't work.

My 'cell' looks like this:

<div class=\"list-element\">
<a class=\"glyphicon glyphicon-link\" href=\"www.somelink\"></a>
<input class=\"btn btn-default\" type=\"button\" value=\"some stuff\">
<label class=\"label label-success\">stuff</label>
</div>

So i want to change "some stuff".

Any help would be greatly appreciated.

Simmer
  • 213
  • 1
  • 3
  • 9
  • 6
    `.find('.btn.btn-default')` – Satpal Oct 20 '16 at 10:03
  • You should an Id to your button and find it by Id. – M.Be Oct 20 '16 at 10:05
  • And a bit more info following @Satpal comment - you you are currently looking for is an element with the `.btn` class that has the element `` inside it (`` doesn't really makes sense, right?). If you want to target element by multiple classes you should use `.class1.class2.class3` – Dekel Oct 20 '16 at 10:06
  • @KevinKloet, read the other comments... and check your code before posting (because it's wrong) – Dekel Oct 20 '16 at 10:07

2 Answers2

4

Try this:

   for (var i = 0, cell; cell = table.cells[i]; i++) {                            
            $(cell).find('.btn.btn-default').val("new value");                  
        }

Remove space in find method

Atul Mishra
  • 298
  • 2
  • 11
1
   for(var i = 0, cell; cell = table.cells[i]; i++) {                            
        $(cell).find('.btn .btn-default').val("new value");                  
    }
DCruz22
  • 806
  • 1
  • 9
  • 18