Friday, 16 August 2013

Use dynamically created html content later with jQuery

Use dynamically created html content later with jQuery

I have a method where I dynamically create a table and assign it to a
local variable:
var content = $('<table id="gvCapitalByYear" cellspacing="0"
cellpadding="2"/>').append('<tbody/>');
Then I have a loop that is meant to add rows to the above created table.
But I can't anyhow get this done. I tried the following:
content=$('#gvCapitalByYear').find('tbody').append('<tr/>');
but it doesn't work, as, in my opinion, an element with id
"gvCapitalByYear" has not been appended to anywhere, it was just created
on the fly and kept in a variable. Is it possible to somehow use the
content variable get the dynamically created table, add certain amount of
rows to and the reassign it back to the content variable again?

No comments:

Post a Comment