data-replace, data-replace-by

Temporarily replaces element contents during an ajax call.


When an ajax call is processing, this is common to see a wait gif to tell the final user his request is processing. data-replace let you replace contents from a selector by contents of another selector during the ajax call. Whatever if the ajax call fails or succeed, old contents will be restaured to the container.
If data-replace is empty, the element containing the ajax call will be replaced itself. If data-replace-by is empty, the element containing the ajax call will replace contents of the data-replace's selector.

data-replace uses data-replace-backup and data-replace-backup-container attributes internally.
data-replace cannot be used alone, without data-replace-by.

Usage


  • data-replace="(target selector)"
  • data-replace-by="(source selector)"

Example


  • data-replace="#output"
  • data-replace-by="#waitgif"

Live examples

This form looks like this:


<div id="gif" style="display:none;">
    <img src="../img/wait.gif" alt="Please wait"/>
</div>

<div id="input">

    <input
            type="button"
            value="Click here!"
            class="btn domajax click"
            data-endpoint="replace-multi-handler.php"
            data-replace=".wait"
            data-replace-by="#gif"
            data-output="#output"
            />

</div>

<br/>

<div class="wait" style="border:1px solid red;margin-bottom:5px;">Some content</div>
<div class="wait" style="border:1px solid blue;margin-bottom:5px;">Some other content</div>
<div class="wait" style="border:1px solid green;margin-bottom:5px;">Some more content</div>

<div id="output"></div>

This form looks like this:


<div id="wait" style="display:none;">
    <img src="../img/wait.gif" alt="Please wait"/>
</div>

<div id="input">

    <input
            type="button"
            value="Click here!"
            class="btn domajax click"
            data-endpoint="replace-itself-handler.php"
            data-replace="#input"
            data-replace-by="#wait"
            data-output="#output"
            />

</div>

<div id="output"></div>


See also    data-callback   data-script 

Table of contents

All the documentation at a glance

Domajax options

And more with domajax