User999999
User999999

Reputation: 2520

Append TD('s) after td element

I currently have the following html:

        <tr>
            <td class="success" rowspan="1">Viability</td>
            <td data-rowh="-Checksum">Viability-Checksum</td>
        </tr>
        <tr>
            <td data-rowh="-Request">Viability-Request</td>
        </tr>

What i want to do is to add columns after each td with the data-attribute data-rowh. So It would look like this (testdata):

        <tr>
            <td class="success" rowspan="1">Viability</td>
            <td data-rowh="-Checksum">Viability-Checksum</td>
            <td data-check="P1-Checksum">Test P1</td>
            <td data-check="P2-Checksum">Test P2</td>
            <td data-check="P3-Checksum">Test P3</td>
            <td data-check="P4-Checksum">Test P4</td>
            <td data-check="P5-Checksum">Test P5</td>
        </tr>
        <tr>
            <td data-rowh="-Request">Viability-Request</td>
            <td data-check="P1-Request">Test P1</td>
            <td data-check="P2-Request">Test P2</td>
            <td data-check="P3-Request">Test P3</td>
            <td data-check="P4-Request">Test P4</td>
            <td data-check="P5-Request">Test P5</td>
        </tr>

I presumed it would work using the following function (apperantly not)

        $('[data-rowh]').each(function (rIndex, rValue) {
            $.each(data.items, function (index, value) {
                rValue.after("<td data-check='" + value.name + "-" + rValue.data("rowh") + "'>test " + value.name + "</td>");
            })
        });

When I use the after() function for rIndex or rValue, i'm getting the error: the property of the method after is not supported by this object. Any idea on what i'm doing wrong?

Note: for those interested milestones looks like:

"items" : [  
{  "msId": "000104",  "name": "P1",  "msdescription": "Augustus" }
{  "msId": "000105",  "name": "P2",  "msdescription": "Descr" }
{  "msId": "000106",  "name": "P3",  "msdescription": "Test" }
{  "msId": "000107",  "name": "P4",  "msdescription": "456798" }
{  "msId": "000108",  "name": "P5",  "msdescription": "Autumn" }
]

Upvotes: 0

Views: 78

Answers (1)

Anthony Grist
Anthony Grist

Reputation: 38345

In a .each() loop over a jQuery object, you're working with the actual DOM node when you reference the value (or this), not a jQuery object. In order to use jQuery functions, such as .after(), you need to wrap it in a jQuery object:

$(rValue).after(...);

Upvotes: 1

Related Questions