Title: Javascript callbacks clarification
Last modified: August 30, 2016

---

# Javascript callbacks clarification

 *  [river-clement](https://wordpress.org/support/users/river-clement/)
 * (@river-clement)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/javascript-callbacks-clarification/)
 * Trying to get javascript callback working : favorites_after_button_submit, so
   that I can pop up login modal if user not logged in when they favourite.
 * Website says to add simple-locator script as dependency. Do you mean simple-favorites?
   Neither seems to work. Can you please share more complete example?
 * > Callback Functions
   >  To use the callback functions in your theme’s scripts, **
   > the simple locator** script handle must be added as a dependency when enqueueing
   > your script. **The Simple Locator script handle is simple-locator.** See the
   > WordPress Codex for more information about properly enqueuing scripts.
 * [https://wordpress.org/plugins/favorites/](https://wordpress.org/plugins/favorites/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [physalis](https://wordpress.org/support/users/physalis/)
 * (@physalis)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/javascript-callbacks-clarification/#post-6690339)
 * Hi [@river-clement](https://wordpress.org/support/users/river-clement/) ,
 * since I went through it myself I can explain how to approach this.
 * In order to let something happen after the button has been pressed (= post has
   been added to favorites, NOT removed), you best use JavaScript to e.g. show a
   div with a message as in my case. For the script not to fail because a crucial
   resource from the plugin itself hasn’t loaded, you add simple-locator as a dependency
   for your JavaScript to load. The WordPress Codex helps you understand how you
   best include a script and/or CSS files into your theme, and then you enqueue 
   your script like this:
 * `wp_enqueue_script('script', get_stylesheet_directory_uri() . '/js/script.js','
   simple-locator', '1.0.0', true);`
 * , and inside your script.js you could do something like this:
 *     ```
       function favorites_after_button_submit(favorites){
       	jQuery('.simplefavorite-button.active').after('<div class="fav_success"><i class="fa fa-info-circle"></i>Contract successfully added to your clipboard.</div>');
       	jQuery('.fav_success').fadeIn(1500).delay(5000).fadeOut(1500);
       }
       ```
   
 * – does that help you out? It is working in my case (showing a message after user
   added fav, disappears again after 5 seconds).
 * Best
 * physalis
 *  [physalis](https://wordpress.org/support/users/physalis/)
 * (@physalis)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/javascript-callbacks-clarification/#post-6690340)
 * PS: Of course, you have to style the div, foremost to not appear on loading for
   it to fadeIn if this is your desire :).
 *  [bluantinoo](https://wordpress.org/support/users/bluantinoo/)
 * (@bluantinoo)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/javascript-callbacks-clarification/#post-9118377)
 * PS: the correct handle is “simple-favorite” not “simple-locator”

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Javascript callbacks clarification’ is closed to new replies.

 * ![](https://ps.w.org/favorites/assets/icon-128x128.png?rev=1677726)
 * [Favorites](https://wordpress.org/plugins/favorites/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/favorites/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/favorites/)
 * [Active Topics](https://wordpress.org/support/plugin/favorites/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/favorites/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/favorites/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [bluantinoo](https://wordpress.org/support/users/bluantinoo/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/javascript-callbacks-clarification/#post-9118377)
 * Status: not resolved