Posted By

jmsrie on 10/15/10


Tagged

jquery


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jmsrie
bobbym245
kubaitis
kwameboame


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


 / Published in: HTML
 

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.

  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  

You need to login to post a comment.