Is it possible to revert the text back upon double-click or when it loses focus?

When I click on a dropdown labeled 'View Capacities', the label changes to 'Hide Capacities'. I am attempting to make it change back to the original label when it is double clicked (when toggle closes) or when the user clicks elsewhere in the window.

My HTML code looks like this:

//JQUERY:

$('.FullLengthDropdown').focus(function(){
  $('.ViewCapacitiesTxt').text("HIDE CAPACITIES");
});

<button class="FullLengthDropdown btn btn-primary dropdown-toggle " type="button" data-toggle="dropdown">
  <div>
    <span class="ViewCapacitiesTxt">VIEW CAPACITIES</span>
  </div>
</button>

<table class="dropdown-menu">
  <tr>
    <th>SPACE</th>
    <th>RECEPTION</th>
    <th>THEATRE</th>
    <th>BANQUETING</th>
    <th>CABARET</th>
    <th>BOARDROOM</th>
  </tr>
</table>

Answer №1

simply include a focus out event!

$('.FullLengthDropdown').focusout(function(){
    $('.ViewCapacitiesTxt').text("VIEW CAPACITIES");
});

Answer №2

Utilize the combination of focusout, dblclick, and toggle() to make this happen.

//jQuery:

$('.FullLengthDropdown').on('focusout dblclick', function(){
  $('.ViewCapacitiesTxt span').toggle()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="FullLengthDropdown btn btn-primary dropdown-toggle " type="button" data-toggle="dropdown">
  <div>
    <span class="ViewCapacitiesTxt">
      <span>VIEW CAPACITIES</span>
      <span style="display:none">HIDE CAPACITIES</span>
    </span>
  </div>
</button>

<table class="dropdown-menu">
  <tr>
    <th>SPACE</th>
    <th>RECEPTION</th>
    <th>THEATRE</th>
    <th>BANQUETING</th>
    <th>CABARET</th>
    <th>BOARDROOM</th>
  </tr>
</table>

Answer №3

Kindly refer to the following source. Notice that when you click on the text below the button, it will toggle back to its original text

 function toggleText() {
                var toggleText = $('.ViewCapacitiesTxt').attr("data-toggle-text");
                $('.ViewCapacitiesTxt').attr("data-toggle-text", $('.ViewCapacitiesTxt').text());
                $('.ViewCapacitiesTxt').text(toggleText);
            }
            $('.FullLengthDropdown').click(function () {
                toggleText();
            });
            $(document).ready(function () {
                $(document).click(function (e) {
                    if (!$(e.target).hasClass("FullLengthDropdown")) {
                        if ($('.ViewCapacitiesTxt').text() != $('.ViewCapacitiesTxt').attr("data-orginal-text")) {
                            toggleText();
                        }
                    }
                });
            });
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <button class="FullLengthDropdown btn btn-primary dropdown-toggle " type="button" data-toggle="dropdown">
            <div>
                <span data-toggle-text="HIDE CAPACITIES"
                      data-orginal-text="VIEW CAPACITIES"
                      class="ViewCapacitiesTxt">VIEW CAPACITIES</span>
            </div>
        </button>

        <table class="dropdown-menu">
            <tr>
                <th>SPACE</th>
                <th>RECEPTION</th>
                <th>THEATRE</th>
                <th>BANQUETING</th>
                <th>CABARET</th>
                <th>BOARDROOM</th>
            </tr>
        </table>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Accessing CouchDB using AngularJS requires users to sign in, with the authentication cookie only being sent to the `/_

Check out my previous posts on this topic here: 1, 2 I currently have an AngularJS app with two controllers. The first one interacts with CouchDB documents, while the second handles sign-in requests to example.com/demo/_session. Upon opening the applicat ...

What techniques can I use to generate a 3D visual effect by shifting the background image layer as the user scrolls (creating a Parallax effect

I have combined two images in the heading; one on top of the other. My goal is to create a subtle vertical movement in the background image as the user scrolls, giving the illusion of depth. Both images share the same width, but the background image is tal ...

Parameter Mapping with Kendo DataSource

As a newcomer to kendo, I am facing an issue with model binding. While debugging with Firebug, I see that options.models is undefined, causing the "if" condition in parameterMap to always return false and preventing the grid from populating with data. Howe ...

"Concealing sibling sections on the same level with JQuery - a helpful guide

As someone who primarily works on backend development, I am fairly new to JQuery. Currently, I have a specific table structure that looks like this: <tr> <td> <div class="div-package-service"><a style="cursor: pointer" id="service ...

Enhance website security with X-ray standard user agent

Currently working on a Node.js application and utilizing the X-Ray library along with Request-X-Ray as a driver. I am curious to find out which user-agent X-Ray uses by default. Can anyone provide insights on this? ...

AngularJS and Spring Rest team up for seamless drag-and-drop file uploads

I have successfully implemented file upload using AngularJS and Spring REST, but now I want to change it to use dropzone.js or any other drag and drop file upload method. I tried using the dropzone.js library, but I am facing issues integrating it with Ang ...

`What is the proper way to retrieve data from ajax.done() method?

Using Ajax, I am retrieving the nickname and attack_point data. var nickname; $.ajax({ method:'GET', url:get_gamestart_api_url, }).done(function(data){ $get_id.append("<li class='nickname&apo ...

Display a pop-up message asking for confirmation within a set duration?

Is there a way to display a confirmation dialogue that is set to expire after a certain time, triggering one of two actions if the user does not respond? Specifically, the confirmation should expire if the user: a) navigates away from the page b) fails t ...

Traverse through a list utilizing a jQuery carousel animation

I am attempting to create a looped list with a carousel effect. It seems like the script should first determine the total number of items in the list in order to perform calculations. Then, it can execute an action such as this: Adding an item on one sid ...

How can I create a script for a sliding/toggling menu?

Not sure if it's appropriate to ask, but I'm currently in search of a slide/toggle menu. Despite my efforts on Google, I haven't been able to find exactly what I need. As someone who is more skilled in HTML/CSS than jQuery or other scripting ...

Guide to parsing JSONP information using Express

I am attempting to transfer data from phonegap to an express application. Below is the code I am using: Phonegap: $.ajax({ type: 'POST', url:"http://127.0.0.1:3000/test", data: {"test":"this works!"}, dataTyp ...

PHP loop causing malfunction in jQuery Tooltip feature

I am trying to enhance my website with tool-tips, and I found this useful code snippet at In order to create table rows <tr>, I have implemented a while loop. The structure of my tool-tip <div> is as follows: <td class="maandgem">&e ...

The vertical tabs in JQueryUI lost their functionality when a few seemingly unrelated CSS styles were added

Check out the JsFiddle demo here I embarked on a mission to craft JQueryUI Vertical tabs by following the guidance provided in this example. The source code within the aforementioned link contains specific CSS styles: .ui-tabs-vertical { width: 55em; } ...

The class type "selectLabel" passed to the classes property in index.js:1 for Material-UI is not recognized in the ForwardRef(TablePagination) component

Just started using react and encountering a repetitive error in the console after adding this new component. Here is the full error message: Material-UI: The key selectLabel provided to the classes prop is not implemented in ForwardRef(TablePagination). ...

Learn the step-by-step process of cropping and zooming an image using the react-image-crop

I am looking to implement zooming and cropping functionality for an image using react-image-crop instead of react-easy-crop. Currently, the cropping does not take into account the zoom level set by ReactCrop's scale property. I want to be able to zo ...

Notifier - The Best HTML Notification System for Web Applications

Currently, I am developing a notification system using Play Framework 2.3 (Java) in combination with MySQL. The system is designed to retrieve notifications from a "notifications" table stored in MySQL database. I initially attempted to use AJAX polling ...

The Full Screen Button on Google Maps isn't functioning properly in a third-party mapping application

Below you will see the '+' icon which is also supposed to function as the full screen button. https://i.stack.imgur.com/IMvHa.png However, when clicked on, it does not expand to full screen as intended. I have attempted using some basic jQuery ...

Issue with adding dynamic keys to state in Next.js using Zustand for state management not resolving

I've been experimenting with dynamically adding a key to a state in zustand. I've attempted various methods such as 1. const store = (set, get) => ({ keyAttrib: {key1: "value1", key2: 2}, update: (key, value) => { let new ...

Ensure that all promises are executed with their inner functions

Is there a way to retrieve multiple HTML bodies simultaneously and only start working with the content once all results are available? I have a callback solution that currently works, here is the code: const request = require('request') const ...

Substituting a JavaScript function with a UserStyle solution

I am currently working on customizing a UserStyle for Instapaper. Since the original UserStyle was created, Instapaper has implemented several JavaScript functions in their header that control page width and font styles. Below are the functions: ...