0

I am trying to prepend some HTML to an AJAX created table. Here is the code:

 success: function (msg) {
 var ang = '';
 var obj = $.parseJSON(msg);
 $.each(obj, function() {
    ang += '<table><tr><td width="165">' + this["Athlete_Name"] + '(' + this["Athlete_Number"] + ')</td><td width="55">'+ this["Scratch_Flag"] +'</td><td width="55">'+ this["Ready_Time"] +'</td><td width="55">'+ this["Flag_Time"] +'</td><td width="55">'+ this["End_Time"] +'</td><td width="55">'+ this["Score_Time"] +'</td></tr></table>';
                    });
                    $('<p>Roster</p>').prependTo('.html(ang)');
                    $('#' + ID ).hide().html(ang).fadeIn('fast');
            }

The Line of code called:

    $('<p>Roster</p>').prependTo('.html(ang)');

Is not appending to my array of HTML that is created called 'ang' could someone point me in the right direction? many thanks

1
  • You're misusing prependTo. You should be using yourelement.prepend(ang) Commented Feb 22, 2013 at 17:29

1 Answer 1

1

jQuery appendTo

If you try add ang to $('

Roster

') element, than you must write some code like this:

$(ang).prependTo('<p>Roster</p>');

But I really don't understand what that code means:

prependTo('.html(ang)')

Can you tell more info about .html command in target selector?

If you try to add <p>Roster</p> element before your table, just put <p>Roster</p> to ang declaration like:

var ang = '<p>Roster</p>';
Sign up to request clarification or add additional context in comments.

Comments

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.