VikingBlooded VikingBlooded - 6 months ago 3x
Javascript Question

jQuery prepend <i> to table row first child

I am having an odd issue, I have several dozen paged with table data that I need to append a font-awesome icon to. Instead of editing every page and having to remember to do it later, I'd rather use jQuery to do it for me. Right now, this is what I have:

$(document).ready(function () {
$(tr.expand td:first:child).prepend("<i class="fa fa-angle-down"></i>");

This works to add the to the first td of each row, but it's adding the 20 times to the element! What am I missing here?


You don't need to use each(). Try like following.

$('tr.expand td:first-child').prepend('<i class="fa fa-angle-down"></i>');