Recording the mouse click action following the turning over of the tile

Greetings! I have successfully implemented a zoom and flip feature on my tile.

My tile now showcases two different views - the initial view displays an image, while the back view shows text.

However, I am encountering an issue where multiple alert boxes are popping up when clicking on the text side. I only want the alert to appear for the text side, not the image side.

I have attempted to add an alert without success and would appreciate some guidance on resolving this issue.

Here is the code snippet I have been working with:

HTML

<div class="wrap" id="html1"><div class="box"><div class="boxInner one clicked"><div class="face front"><img src="img/s.png"></div><div id="SearchDono" class="face back"><label class="text">Search Donors</label></div></div></div><div class="box"><div class="boxInner two two-clicked"><div class="face front"><img src="img/r.png"></div><div id="RegisterDono" class="face back"><label class="text">Register</label></div></div></div><div class="box"><div class="boxInner three three-clicked"><div class="face front"><img src="img/u.png"></div><div id="UpdateDetai" class="face back"><label class="text">Update Details</label></div></div></div><div class="box"><div class="boxInner one clicked"><div class="face front"><img src="img/s.png"></div><div class="face back"><div id="ShareStat" class="text">Share</div></div></div></div></div>

CSS

.wrap {
    overflow: hidden;
    margin: 10px;
    -webkit-transform: translateZ(0);
    position: relative;
    top: 0px;
}

.box {
    float: left;
    position: relative;
    width: 25%;
    padding-bottom: 10px;
}

... (CSS styles continue)

JS:

 $('.box').click(function(){
                $(this).addClass('hai');
            });
            $(".one").click(function(){
                $(this).toggleClass("clicked");
                $(this).addClass('backone');
                $('.backone').click(function(){alert('hai');
                $(this).removeClass('backone');
                });
            });
            $('.two').click(function() {
                $(this).toggleClass("two-clicked");
            });
            $('.three').click(function() {
                $(this).toggleClass("three-clicked");
            });

Demo Link

Answer №1

There are multiple alerts present because of a click event inside another click event

To resolve this issue, try updating the code to the following:

$(".one").click(function () {

    $(this).toggleClass("clicked");

    if ($(this).hasClass('backone')) {    //check if it already has class
        $(this).removeClass('backone');  //remove class

    } else {
        alert("hello");  //if not alert
        $(this).addClass('backone'); //addclass
    }
});

If you need the alert at a different point, feel free to adjust its position in the code accordingly.

You can view the updated code and test it out on this Fiddle: http://jsfiddle.net/u22Mj/4/

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

Utilizing the power of AngularJS in conjunction with the Edmunds Media API to retrieve stunning

Scenario: Utilizing a Rails application and $http.get in AngularJS to retrieve photos from the Edmunds.com MEDIA API. GOAL: To use ng-repeat to cycle through the vehicle photos. ISSUE: While I am able to successfully fetch a single image, I am struggling ...

Dynamic Data Display

I'm experiencing an issue where the data is not displaying in the table div when using an Ajax call to load the table. The page appears blank upon return, and I have tried using $('#groupTable').load(data); without any success. If anyone can ...

Retrieve data using a jQuery select query

Is there a way to use a jquery select function to retrieve the email from a users array that contains additional data for each user? var _userObject = linq.From($vw.listVwObservable().Users()); After executing this code, I get an Array[6] where each ele ...

Use Select2 for efficient selection

I am attempting to implement select2 for a multi-select dropdown list of states, but I am encountering an issue. Typically, when you type in an option, it should be highlighted so that you can press enter to select it. However, in my case, it underlines t ...

Can a gulpfile be written in ES6 syntax?

Question: Is there a way to write my gulp file in ES6 to utilize import instead of require, and use => syntax in place of function()? I have the option to use io.js or any version of node.js. gulpfile.js: import gulp from "./node_modules/gulp/index.j ...

Implementing jQuery autocomplete feature by fetching data from a server using JSON/AJAX

I am seeking an answer. In PHP, I have developed a web app with a list of records and search fields. One of the search fields is "customernumber", which pulls data from a MySQL database. When searching for a customernumber, it retrieves the corresponding ...

What is the process for programmatically importing a module into the local scope in Node.js?

The coding environment is using a browser and the bundle tool being used is webpack. In my router.js file, I have the following code: import foo from './views/foo.vue' import bar from './views/bar.vue' import zoo from './views/zoo. ...

The Angular ng-style feature is responsible for applying a style attribute that is subsequently not maintained in proper sync

My angular website retrieves data from a Web API as its back end. Initially, a generic background is displayed. However, after the user logs in, the background image URL specific to the customer is fetched and utilized in the ng-style attribute. Upon the ...

What is the best way to display JSON data in a Django template?

Looking to extract data from a URL in this format: http://www.example.com/data?format=json The output will resemble the following structure: student_details: { terms: { subjects: { assigments: { id:11, name:"ass_1 ...

Opening a window in ExtJS when another window is already open

It seems like I'm having trouble opening a new window on top of another window that is already open in ExtJS 6. I have tried setting the model to true and bringToFront to true, but unfortunately, neither of them is working as expected. https://i.sstat ...

Monitor the element's height for any changes and update it accordingly on a separate element

Is there a way to accomplish the following: I currently have a navigation bar with the class of "navbar-fixed-top", and I've also added a style of min-height: 50px; Beneath the navigation bar, I have a content section with a class style of padding-t ...

Encountered npm error! Issue arose while resolving: [email protected] npm error! Detected: [email protected] during npm installation

I encountered an error while trying to install a project on my new PC using npm. The same project worked perfectly on my old laptop, but now I'm facing this issue. npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While re ...

Challenges when upgrading from Ext JS 3 to Ext JS 4

I am looking to upgrade my code from Ext JS 3 to Ext JS 4. I used the Ext.Updater class in Ext JS 3, but I cannot seem to locate a similar functionality in Ext JS 4. Can anyone provide assistance with this transition? ...

Is there a way to prevent an ajax call from refreshing the page?

I've implemented image upload functionality in my project. However, when I click the upload button and select a file, the images are displayed via an AJAX call with HTML code. Unfortunately, afterwards, the page refreshes and all form data is lost. E ...

Is it possible to combine EJS compilation and html-loader in the html-webpack-plugin?

I need the html-webpack-plugin to generate my html using my .ejs template that contains <img> tags. The html-loader can update the image URLs in my <img> tags created by Webpack, so I am including it in my configuration: test: /& ...

Utilizing a function to populate an attribute using .attr() in d3

I utilize .attr to generate link paths in D3, as demonstrated in Lines 42 of the live demo: link.each(function (d){}) .attr('x1', function (d) { return d.source.x; }) .attr('y1', function (d) { return d.source.y; }) .a ...

bootstrap v4 push pull missing

Exploring the latest updates in Bootstrap v4: https://getbootstrap.com/docs/4.0/migration/#grid-system-1 ...The push and pull modifier classes have been replaced by the new flexbox-powered order classes. For example, instead of .col-8.push-4 and .col-4 ...

Automated web browser capture downloading feature

Currently, I am in the process of developing a tool to streamline tasks at my workplace. One feature we need is an aspx webpage where users can input information, then click on a submit button. When the submit button is clicked, a javascript download dialo ...

Converting XML to JSON in a Node.js application

I recently read an article on that explained the conversion process clearly, but unfortunately it's not working for me. Let me provide you with the code snippet: function parseXml(xml) { var dom = null; if (window.DOMParser) { try ...

Integrating WordPress nonce into a basic AJAX function: a step-by-step guide

I am currently working on creating simple plugins with ajax in WordPress. I have created a button labeled "like" for posts that is supported by some people. However, I am facing an issue: 1. I have been trying to secure it with a nonce, but despite search ...