Skip to content

$.load()

Arthur Guiot edited this page Aug 5, 2017 · 1 revision

How it works?

This function will basically update a specific element in the DOM from the server.

You can see this function as a smart reload.

Here is how you can use it:

  • You can load fragments of the page
  • You can update dynamic elements from the servers.

How to use it?

This function will require 3 arguments:

  • el - This will be the selector (don't use $.s() method for this.)
  • url - Where to fetch the content
  • callback (optional) - What to do next?

Example

HTML (Client):

<h1>My Goals</h1>
<div class="load"></div>

HTML (Server):

<div class="load">
	<p>Understand DisplayJS</p>
    <p>Star ⭐️ DisplayJS on GitHub</p>
</div>

JS:

$.load(".load", "projects.php")
Clone this wiki locally