How to replace value in td using jquery/php?

Solution:1

With the selector [colspan="6"] you can get to each and set a new attribute:

 

$('.shop_table [colspan="6"]').each(function() {
  this.setAttribute('colspan', '4');
});
console.log($('table').html());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="shop_table">
   <thead>
       <tr><th></th></tr>
   </thead>
   <tbody>
    <tr class="aa"><td></td></tr>
    <tr class="bb"><td></td></tr>
    <tr class="cc" colspan="6"><td></td></tr>
   <tbody>
</table>

Solution:2

You can use prop() or attr() and both methods will loop through all of them

 

$('.shop_table td[colspan="6"]').prop('colSpan', 4)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="shop_table" border=1>
   <thead>
       <tr><th>111</th><th>111</th><th>111</th><th>111</th><th>111</th><th>111</th><th>111</th></tr>
   </thead>
   <tbody>
    <tr><td class="aa">222</td></tr>
    <tr><td class="bb">333</td></tr>
    <tr><td class="cc" colspan="6">444</td></tr>
     <tr><td class="aa">222</td></tr>
    <tr><td class="bb">333</td></tr>
    <tr><td class="cc" colspan="6">444</td></tr>
   <tbody>
</table>

Solution:3

Hey a simple answer to your question is this:

$("table tr:last td[colspan=6]").attr('colspan',4);

I select the Table, then the last TR, and then the TD representing the one you want to be changed.

Then I add the attribute colspan 4.

This is a codepen showing it working: https://codepen.io/SweetChillyPhilly/pen/MWJbBPo

And here is the SO question where you can read more about how this solution became to be Replacing Colspan = “2” with Colspan = “4” using Jquery