Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Writing td on the table

Hi, Experts, I wish to write something on the td of the table whos id is myProlist3. How could I make  it with the codes below?  In the codes below, I want to do something like this td:eq(1).html = b;

<script>
$(function() { 
  $(document ).on("click","#myProlist3 button.NewQty14",function(){
    let tr = $(this).closest('tr');
    let a = tr.find('td:eq(0)').html(); 
    let b = tr.find('input')[0].value; 
    //This is what i need
    td:eq(1).html = b;
  });
});

</script>

Open in new window

Avatar of Swatantra Bhargava
Swatantra Bhargava
Flag of India image

Try below and test
$('#myProlist3 td:nth-child(1)').html(b);

Open in new window

Avatar of Whing Dela Cruz

ASKER

Hi, sir, it's working but the problem is.. the entire row will be written. Is there anyway here that only the row index will be filled up? Thanks!
You can try with tr index too
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, Julian, thank you so much, your code its working on my project, but I want to add one more question here, I want to change the background-color of the td like tr.find('td:nth-child(4)').html = background-color: white;

  $(document ).on("click","#myProlist3 button.NewQty14",function(){
    let tr = $(this).closest('tr');
    let a = tr.find('td:eq(0)').html(); 
    let b = tr.find('td:eq(1)').html();
    let c = tr.find('input')[0].value;
    tr.find('td:nth-child(4)').html(c);
    // I want to do like this
    tr.find('td:nth-child(4)').html(background-color: white);
  });

Open in new window

Why do you want to do this in script? Why not in CSS?
tr td:nth-child(4) {
   background-color: white;
}

Open in new window

Hi, Julian, Its hard for me to explain why I need it to do in script rather than in css. My project is still using css as well. All I can say here is thank you so much for your help and guide.