How do I get value in the td tag in jquery?

0

How do I get the value 1 and manipulate it, by jquery, that is inside the td tag (I want this value to increase as I click an id = 'add-row' button):

 <td>1</td>     
    
asked by anonymous 18.10.2015 / 20:36

2 answers

1

You can use $('td').html() to read and $('td').html('novo valor') to change ...

Depending on your HTML you should be more specific in the $('td') selector because you will then select the td all. To increase the value each time an element is clicked you have to use an event dropper, and I suggest you save that count in JavaScript in the example below. But without knowing the rest of the code I can not guess much more.

var contador = 0;
$('#add-row').on('click', function(){
    contador++; // somar +1
    $('td').html(contador);
});

Example: link

    
18.10.2015 / 21:01
0

You can use custom filtering. See:

var text = $("td").filter(function(){
    return $(this).text() === "I";
}).text();

console.log("Text: " + text)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table><tr><td>I</td></tr></table>
    
18.10.2015 / 20:47