jQuery .load() - special feature that we should know


/ Published in: HTML
Save to your folder(s)

First, we select the link with an ID of #some_id, and prevent the default event from occurring (which would be to follow the link and load the target page). We grab the original destination of the link (by retrieving the href attribute of the link we clicked on), and pass it onto the load function.


Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. $('a#some_id').click(function(e) {
  3. var url = $(this).attr('href') + ' #content';
  4. $('#call_content').load(url);
  5. e.preventDefault();
  6. });
  7.  
  8.  
  9. <div id="call_content">
  10. This will be replaced with the texts inside the div#content when run! link is clicked.
  11. </div>
  12.  
  13.  
  14. <div id="content">
  15. This content will be loaded to div#call_content
  16. </div>
  17.  
  18. <a id="some_id" href="index.html">run!</a>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.