Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can attach a click function to the div like so:</p> <pre><code>$('#feedback').html("&lt;h2&gt;Your message has been sent!&lt;/h2&gt;") .append("&lt;p&gt;Click anywhere to hide this message.&lt;/p&gt;") .hide() .fadeIn() .click(function(){ // Hide the div and remove it $(this).fadeOut(function(){ $(this).remove(); }); )}; </code></pre> <p>Or if you'd just like to auto hide the message you could use the jQuery <code>delay()</code> function or simply <code>setTimeout</code>. Here's how you'd use the <code>delay()</code> function:</p> <pre><code>$('#feedback').html("&lt;h2&gt;Your message has been sent!&lt;/h2&gt;") .append("&lt;p&gt;Click anywhere to hide this message.&lt;/p&gt;") .hide() .fadeIn() .delay(1000) .fadeOut(); </code></pre> <p>Alternatively here's an example using a <code>setTimeout</code> funciton:</p> <pre><code>setTimeout(function(){ $('#feedback').hide(); }, 1000); </code></pre> <p>The <code>1000</code> here relates to the number of milliseconds to wait before executing the code.</p> <pre><code>1000 miliseconds = 1 second </code></pre> <hr> <p><strong>EDIT:</strong></p> <p>Ok so to make sure you're not replacing the form you need to append the message instead like this:</p> <pre><code>$('#send-message').append("&lt;div id='feedback'&gt;&lt;/div&gt;"); </code></pre> <p>You can also temporarily hide the form and then show it once you're user has dismissed the feedback message:</p> <pre><code>$('#send-message form').hide(); // Add show form to the click function .click(function(){ // Hide the div and remove it $(this).fadeOut(function(){ $(this).remove(); $('#send-message form').show(); }); )}; </code></pre> <hr> <p><strong>FURTHER EDIT:</strong></p> <pre><code>// Simple jQuery Plugin $.fn.clearForm = function() { $this = this; // Find inputs $this.find('input[type=text], select').val(''); $this.find('input[type=checkbox]').removeAttr('checked'); }; // Usage $('#form').clearForm(); </code></pre> <p>Example here: <a href="http://jsfiddle.net/dUQ9T/5/" rel="nofollow">http://jsfiddle.net/dUQ9T/5/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload