Playing with Jquery, I need to add and table inside another existing table, and after some fight with the code, I realized that the “trick” would be add the content of the remote table, inside a TD.
So here are the steps :
1. make the TD hidden, because we don’t want an empty TD taking space in the table. use style=”display: none;” in the TD definition.
2. create an external file that will be inserted in the TD, I called it mytable.html.
3. identify the TD so we can manipulate it by it’s ID, for example something like : id=”data_item”
4. add the links to insert the data in the TD
errrr, why to first make the call and then create the code itself ? I don’t know you can change the other if this bugs your brain… hehehe.
5. create the code to load the data and hide it.
6. dont forget to include the jquery library in your page:
Now that you followed the steps and didn’t work, lets go step by step in the jquery code
this snipet of code $(‘#data_item’) selects the elements that have the id=data_item, to selec elements by the class would be something like $(‘.data_item’) but in this case we want to deal with only one item, that has the ID=data_item, so we use the # in the string selector.
the function load() is used to make a remote call to an URL and load, as the name says, the content of the URL in the selected element, it could be a DIV, a SPAN, All the content of a table, but in this case we are loading in a TD.