I would like to create a simple webpage with a 2-column design, using some combination of HTML / CSS / Javascript / jQuery, in which one column contains a navigation menu with several links, and clicking on the links changes the content of the other column. What's the best way to do this nowadays?
A long time ago, I learned to do this with frames, with the menu in one frame and the content in another, and the menu items surrounded by anchor tags of form <a href="something.html" target="name-of-content-area">
. I guess this way is still possible?
Some people recommend making the menu and content areas be divs instead of frames, and then putting an iframe inside the content div. The menu item links are then done in the same way just described.
Still other people recommend using divs only - no frames or iframes - and using Javascript to change the content in the content area, i.e. the anchor tags take a form like <a href="#" onclick=func>
where func dynamically changes the content in the content area.
Finally, some people recommend using divs only and using buttons instead of anchor tags in the menu, and once again using Javascript attached to the buttons to adjust the content area content.
I guess there are more options I've missed. Is there a generally accepted modern best practice, if so is it one of those I've listed, which one, and why? If there's not a single best practice, what are the situations or reasons for using each of the alternative "good" options?
There are various ways to do this:
Options 1 and 2 are self-explanatory. The advantage of 2 over 1 is that bookmarking and browser history are nice and simple. A lot of folks are veering towards 3 now.
Here's a simple JSFiddle I put together as an example of option 3. It's ugly, yes, I didn't bother styling anything.
http://jsfiddle.net/sJ6Bj/4/
Here's the HTML:
JavaScript (assumes JQuery is loaded):
CSS:
As @RobG said above, the browser considers it all to be one page currently. However, with something like JQuery BBQ, that can be added back in without much effort (e.g. see here).
Why would one choose divs over frames? There are various reasons.