Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

Populating table with database and attaching element to each <tr>

I want to add functionality to each <tr> tag inside a table. Then use jQuery and when a <tr> element is clicked on/toggled an additional piece of information is shown. Each <tr> is dynamically generated when looping through the entries from the database, so which tag would this new element be appended.

Would this pose a problem as the the content for the additional element would have to someone be passed through jQuery?

Any ideas other methods to achieve this result?

Thanks =)

1 Answer

I'm not sure I completely understand what you're trying to do, but you can use jQuery and Ajax to 'dynamically' get new content from the database, by using something on the server side (PHP, Node.js or whatever) to query and return the results from the database.

Shouldn't be any issues, as long as the content is accessible from the same host/domain. If it's from another domain (or even port or protocol), you might get errors relating to the same-origin policy.