1

I am looking at a JS file from a colleague who has since left my work place so have no access to them.

//populate the inheritance table but remove all rows first
$("#reportBeneficiariesTable tbody").html("");

$(".saved-beneficiary").each(function() {
        $( "#reportBeneficiariesTable tbody" ).append( "<tr style=\"height:40px\">" + 
        "<td>"+$(this).find(".name").html()+"</td>" +
        "<td>"+$(this).find(".relation").html()+"</td>" +
        "<td>"+$(this).find(".inheritanceVal").html()+"</td>" +
        "<td>"+$(this).find(".taxableInheritance").html()+"</td>" +
        "<td>€"+$(this).find(".taxLiability").html()+"</td>");

I am trying to use the variable for .name as a span class to bring in the input Name further down the page? I thought this could be achieved by this:

 $('.name-1').html(name);

But doesn't seem to work? Any help would be appreciated

2
  • What do you want exactly? Could you describe the desired output? Commented Sep 11, 2018 at 8:41
  • I would like to be able to take the value that is input in the <td> "<td>"+$(this).find(".name").html()+"</td>" . Which is a Name and output it in a sentence in the page for example, <span class="name-1"></span> is my name. Commented Sep 11, 2018 at 8:44

1 Answer 1

1

You may use CSS as well. If you are allowed to use CSS you may transform the table's rows into flexbox and change the order of the <td>s inside, for example like this:

table *{border:1px solid #d9d9d9;padding:.5em;}

table{display:block;}
table tr{display:flex;}
.name{order:1}
<table>
<tr>
<td class="name">name</td>
<td class="relation">relation</td>
<td class="inheritanceVal">inheritanceVal</td>
<td class="taxableInheritance">taxableInheritance</td>
<td class="taxLiability">taxLiability</td>
</tr>
</table>

Sign up to request clarification or add additional context in comments.

5 Comments

I wouldn't be too confident replacing the previous javascript in case it affects something elsewhere.
How can I then call the span for name elsewhere. I have replaced the table with your example and get the output I have entered earlier in the form, but when i try <span class=name"> it won't work?
I'm not very sure I understand you. You don't have a <span class=name"> you have a <td class="name">. You may call it by it's class or by it's position in the markup. Please add an example of what you want to do
If I have that table above. I would like for a sentence below to say. My name is John and my relation is Child. The 'John' and 'Child' would be taken from the table. If that makes sense
conye9980 This is an entirely different question. If you liked my previous answer please accept it and ask a new question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.