Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialScott Wilcox
9,517 Pointslink_to, <%= yield %>, and javascript
The page I am working on has a set header, footer, nav, and display containers.
I am currently using this javascript to load links into the main content div without reloading the entire page.
// Loads external subpages to the div id="mainContent" on a href="" mouse click
$(document).ready(function(){ $('a').click(function(e){ e.preventDefault(); $("#mainContent").load($(this).attr('href')); }); });
can this be used with the link_to and only have the "yield" tag in that container div?
1 Answer
Seth Reece
32,867 PointsI'm not an expert, but it seems to me this should work. As long as Ruby is building a div with the right class or id, JavaScript should be able to target it. Essentially, when Ruby loads on a server, it compiles your code into html that the browser can read.