How to reload a value in only one row of a table

I have a table, and there is some data in the tables, and I have an update button in the last column of each row.

what i want is when i press update button in some line, only this line should reload.

but now, what happens when I click the refresh button, each line becomes reloaded ,,

How can it be?

Here is the code I used:

<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(".b1").load("content.txt");
    $(".b2").load("content1.txt");
  });
});
</script>
</head>
<body>


<table border="1">
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
<tr><td class="b1"></td><td class="b2"></td><td class="b1"></td><td class="b2"></td><td class="buto"><button>Refresh</button></td></tr>
</table>
</body>
</html>
+1
source share
2 answers

use the thislink

$("button").click(function(){
  $(this).parents('tr').find(".b1").load("content.txt");
  $(this).parents('tr').find(".b2").load("content1.txt");
});

or

$("button").click(function(){
  $(this).parent().siblings(".b1").load("content.txt");
  $(this).parent().siblings(".b2").load("content1.txt");
});
+2
source

$(".b1")and $(".b2")select each item with this class. You need to filter based on the row in which the button is used:

$("button").click(function(){
    var $row = $(this).closest("tr");
    $row.find(".b1").load("content.txt");
    $row.find(".b2").load("content1.txt");
});
+1

Source: https://habr.com/ru/post/1623701/


All Articles