0

I am trying to apply class to all date items in a loop. My code is working but i am 100% sure that they way i wrote code is not right. Could some on suggest on the code changes. I want to use a FormatDateTime function(my own function) on date item in a loop. As this is a class can we get rid of .each loop in jquery?

for (int i = 0; i < Value.Count; i++)
            {
                <tr>

                    <td class="ModificationDate">@MDate</td>

                    <td>@Action</td>
                    <td>@Field</td>
                    <td>@Value</td>
                </tr>
            }

<script>
    $(document).ready(function () {
        $("[class=ModificationDate]").each(function () {
            $(this).text(FormatDateTime($(this).text()));
        });
    });
</script>
Kurkula
  • 6,386
  • 27
  • 127
  • 202

1 Answers1

0

Your code works fine, look at this JSFiddle Demo.

But you can do that in a better way like this:

$(document).ready(function () {
    $ModificationDate = $(".ModificationDate");
    $ModificationDate.text(FormatDateTime($ModificationDate.text()));
});

Check JSFiddle Demo

Moshtaf
  • 4,833
  • 2
  • 24
  • 34