javascript - partial page update with navigation -
first of all, apologize because first time trying code website (or anything), might stupid question. have web page update single div when link in navigation bar clicked.
<body> <div id="wrapper"> <header id="header"> </header> <section id="section1"> <div> </div> <nav id="mainnav"> <ul> <li> <a href="1.html"><b>1</b></a> </li> <li> <a href="2.html"><b>2</b></a> </li> <li> <a href="3.html"><b>3</b></a> </li> </ul> </nav> </section> <section id="section2"> <div id="mainwrap"> <div id="main"> </div> </div> </section> </div> </body> </html>
i know, it's lot of useless stuff, point. i'm trying click on 1, 2, 3, etc., content of div "mainwrap" changes, url (so page not refresh, url changes www.website/1.html website/2.html, etc. , content of 1 div changes). have different html files 1, 2, , 3, each different "main" divs, ideally inserted "mainwrap."
i've tried following along tutorials https://css-tricks.com/rethinking-dynamic-page-replacing-content/ , other stackoverflow posts how partial page update jquery. second 1 seems want do, when try implement it, still doesn't work. there simple fix missing because don't know coding? (also, i'm using dreamweaver. don't know if makes difference.)
thanks!
you right how partial page update jquery need. assume new jquery stuff here complete markup http://jsfiddle.net/yrbvnayy/ job done!
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="edit-type" edit="text/html; charset=utf-8" /> <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script> </head> <body> <div id="wrapper"> <header id="header"> </header> <section id="section1"> <div> </div> <nav id="mainnav"> <ul> <li> <a href="1.html"><b>1</b></a> </li> <li> <a href="2.html"><b>2</b></a> </li> <li> <a href="3.html"><b>3</b></a> </li> </ul> </nav> </section> <section id="section2"> <div id="mainwrap"> <div id="main"> </div> </div> </section> </div> <script type="text/javascript"> $("#mainnav li a").click(function(e) { // prevent going page e.preventdefault(); // href var href = $(this).attr("href"); $("#main").load(href, function() { // after content has been loaded }); }); </script> </body> </html>
Comments
Post a Comment