What could be the reason for event.stopPropagation() not functioning properly with a switch statement

Could you please explain why the function event.stopPropagation() is not working on the switch element?

Whenever I click on the switch, it prints the console log for the switch. However, when I click on the surrounding area (row), it logs the row event instead of the switch event. Any idea why this happens? http://jsfiddle.net/k7zJ4/

$(function(){
$('#testSuitConfiguration').click(function () {

console.log('pp')    

});

  $( ".selectSequenc_h" ).on( "change", function(event, ui) {
        //alert('pp')
        console.log('==')
        event.stopPropagation();
    });
});

Answer №1

Here is a live example you can test out: http://jsfiddle.net/pT2bU/1/

JavaScript

$(document).on('pageinit', '#home', function(){ 
    $(document).on('vclick','#testSuitConfiguration',function () {
        console.log('pp')    
    });
    
    $(document).on( "slidestop", ".selectSequence_h" ,function( event, ui ) {
        console.log('==');
        event.stopPropagation();
        event.stopImmediatePropagation();
    }); 
});

In this code snippet, I have used jQuery Mobile's vclick event instead of the traditional click event for better compatibility on both desktop and mobile browsers while avoiding issues with event propagation.

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

employing a flexible array of gulp operations in run-sequence

I have a situation where I need to create gulp tasks with dynamic names and ensure that they run in sequence, not parallel. I have stored the task names in an array, but when I try to use run-sequence, I encounter an error. I suspect the issue lies in how ...

Issue encountered while trying to implement a recursive function for mapping through nested elements was not producing the

I am currently working on recursively mapping through an array of nested objects, where each object can potentially contain the same type of objects nested within them. For example: type TOption = { id: string; name: string; options?: TOption; } con ...

The NodeJS expressJs Server is unable to receive JSON data

Here is how my ajax request is structured: $.ajax({ url: baseURL, type: 'POST', data: JSON.stringify(sendData), contentType: 'application/json; charset=utf-8', dataType: 'json', async: false, succe ...

Exploring the world of promise testing with Jasmine Node for Javascript

I am exploring promises testing with jasmine node. Despite my test running, it indicates that there are no assertions. I have included my code below - can anyone spot the issue? The 'then' part of the code is functioning correctly, as evidenced b ...

Leveraging the power of Ajax to dynamically submit a single form nested within a forEach iteration

I'm currently working on a database query that retrieves all user posts. This query is then used in a forEach loop to generate a post for each result: for($indexPost=0; $indexPost < $postCount; $indexPost++) { //Code for handling the post echo&l ...

I just finished crafting a dynamic line chart with d3.js within a React environment. However, I am now looking to add some personalized touches to enhance its appearance. Could you kindly review the details and code

I want to create a line chart using React and D3, similar to the one depicted in this image. Presently, I have partially implemented the chart with the code provided below. You can see it here. The code snippet I've developed so far is outlined as f ...

What is the process for adding content to a JSON object?

I may have a simple question, but I'm new to backend development and I'm trying to figure out how to post in JSON format. Here is the JSON schema I am working with: email: { type: String, unique: true, lowercase: true, required ...

Include the url of the html file in your JavaScript code

I have a piece of code that I want to include in my JavaScript instead of HTML. The code is as follows: <script async src="https://www.googletagmanager.com/gtag/js?id=ID"></script> Since all my functions are written in JavaScript, I ...

Setting up PhpStorm for Global NPM module resolution

I'm in the process of developing a WordPress plugin, and the directory path I'm focusing on is: wp-content/plugins/pg-assets-portfolio/package.json I currently have the NodeJS and JavaScript support plugins installed (Version: 171.4694.2 and V ...

The problem of asynchronous communication in Ajax

Currently, I am in the process of developing a mobile application using backbone.js. The main functionality of the app involves users selecting football players for a team. To enhance user experience, I aim to implement a feature that remembers player sele ...

Directing users to a specific section on another webpage can be accomplished using HTML, JavaScript, or

<nav> <div class='container-fluid'> <h1 class='logo'>Logo</h1> <ul class='list-unstyled naving'> <li><a href='index.html'>Home</a></li> ...

Tips on transferring a Rails variable to Ajax

Struggling to integrate a progress bar (Javascript) into my Ruby on Rails application, I am facing difficulties in passing values from the controller to JS for updating the bar. In my initial attempt, I used a basic global variable ($count), but it remain ...

Wordpress is having issues running jQuery

I've developed a function inside js/custom.js. The purpose of this function is to arrange posts in my Wordpress site by applying a class called articleAlign. This class will enhance the spacing between the article title and its excerpt, but only when ...

React Select only enabling single selection at a time

Currently, I am in the process of updating my react app to version 16.8 and also updating all associated libraries. One issue that has come up is with two drop-down selects from Material UI. Since the update, the multi-select option no longer allows multip ...

Troubleshooting Routing Issues in a Next.js Website Tutorial

After going through the next.js tutorial at https://github.com/zeit/next-learn-demo.git, I encountered an issue starting from stage 3 "dynamic routing". Despite the tutorial indicating that dynamic routing should be working from stages 3 to 8, it wasn&apos ...

Using React.js to add MongoDB documents into the database

Is there a way to directly insert documents into a MongoDB collection from a React component? I have been working on a personal project, which is a chat web application used for training purposes. For instance, when a user wants to post a new message in a ...

Reset the input field upon button press

Is there a way to clear the input field after pressing the button? <div class="form-group autocomplete"> <div class="input-group search"> <input id="search" name="searchterm" type="search" class="form-control form-control search-input" pl ...

Tips for transferring large data without a page redirect using jQuery's post method:

Seeking advice on how to send large data via jQuery POST without redirecting the page. I'm working on a mobile chat project where communication between user app and server is done using JSON. The issue arises when dealing with big data as the jsonGet ...

Utilize Javascript to create a function that organizes numbers in ascending order

Is there a way to modify this code so that the flip clock digits appear in ascending order rather than randomly? $( '.count' ).flip( Math.floor( Math.random() * 10 ) ); setInterval(function(){ $( '.count' ).flip( Math.floor( Math.rand ...

Create a list using ng-repeat in AngularJS, each item separated by "custom categories"

I am looking to create a dynamic list that will display values entered by users, categorized by custom categories. The challenge is that I do not know in advance which category each element will belong to. Here's an example of how I envision the list ...