I am trying to change the value of an td
value with the button that is clicked.. I have tried a couple of ways but none have worked. If user click Show USD
button column show only USD
values, If user click GBP
column should show GBP
values. I don't know this this is correct way to do this. Any help highly appreciated.
$('.btn-usd').on('click', function(){
$("cu-usd").removeClass(hide);
$("cu-gbp").addClass(hide);
});
$('.btn-gbp').on('click', function(){
$("cu-gbp").removeClass(hide);
$("cu-usd").addClass(hide);
});
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn-usd">show USD</div>
<div class="btn-gbp">show GBP</div>
<table>
<tbody>
<tr>
<td>
<div class="cu-usd">$10</div>
<div class="cu-gbp">£7.10</div>
</td>
<td>
<div class="cu-usd">$20</div>
<div class="cu-gbp">£14.20</div>
</td>
<td>
<div class="cu-usd">$30</div>
<div class="cu-gbp">£21.30</div>
</td>
<td>
<div class="cu-usd">$40</div>
<div class="cu-gbp">£28.10</div>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>
<div class="cu-usd">$100</div>
<div class="cu-gbp">£70.10</div>
</td>
<td>
<div class="cu-usd">$200</div>
<div class="cu-gbp">£140.20</div>
</td>
<td>
<div class="cu-usd">$300</div>
<div class="cu-gbp">£210.30</div>
</td>
<td>
<div class="cu-usd">$400</div>
<div class="cu-gbp">£280.10</div>
</td>
</tr>
</tbody>
</table>
The jQuery attr () method is also used to set/change attribute values. The following example demonstrates how to change (set) the value of the href attribute in a link: The attr () method also allows you to set multiple attributes at the same time.
Also, you can click the "Edit" link under the "Option" column and the whole row will become editable. And edit link will be replace with "Save | Cancel |". Let's dissect this whole editable process so you can use it in your own web projects. Let's assume that you got your table data via ajax call in jquery and it has the following array:
Introduction to jQuery Data Table jQuery DataTable is a powerful and smart HTML table enhancing plugin provided by jQuery JavaScript library.
There is a Input Element, the task is to set its value using JQuery. Here are a few examples discussed. To understand example first few methods to know. JQuery val() method: This method return/set the value attribute of selected elements. If we use this method to return value, it will return the value of the FIRST selected element.
There are 2 problems
.
Following will work
$('.btn-usd').on('click', function(){
$(".cu-usd").removeClass("hide");
$(".cu-gbp").addClass("hide");
});
$('.btn-gbp').on('click', function(){
$(".cu-gbp").removeClass("hide");
$(".cu-usd").addClass("hide");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With