Change td value after validation

1

I have the following HTML code

<table>
<tr>
<td class="x">10</td>
<td class="x">10</td>
<td class="x">12</td>
<td class="x">18</td>
</tr>
</table>

Using jquery I can get and check what the value inside <td> is using the following function:

$(".x").text(function(index, item){
console.log(item);
{

How do I check if <td> has the value 10 , and so exchange the 10 value for a string, and then play into <td> which has the value 10 back with value changed?

    
asked by anonymous 24.10.2016 / 00:47

3 answers

2

Try this:

$('#appendButton').click(function(){
    $( ".x" ).each(function( index ) {
  if($(this).text() === "10"){
  $(this).html("VDC");
  }
});
});
    
24.10.2016 / 01:49
1

You can do something like this:

if (parseInt(item.innerHTML) === 10) {
  var novoValor = 50; // Implemente aqui a lógica do novo valor
  item.innerHTML = novoValor;
}

You can get content inside the div using innerHTML .

    
24.10.2016 / 01:43
0

Do not forget to add an ID to improve element identification. But I think whatever you want is something like this:

$(function(){ // just jquery init
  $('table').find('td').each(function (index, item) {
    var itemContent = $(this).html()
    console.log( itemContent );
    if ( itemContent == 10 || itemContent == '10' ){
        // do something here
       console.log( item, index );
    }
  });
})
    
24.10.2016 / 04:29