The method $event.stopPropogation doesn't seem to be functioning properly

I am facing an issue where the functionality of a div is affected when clicking on an input box inside it.

When the div is selected and colored red, clicking on the input box within the selected div causes the div to become unselected (grey in color).

I tried using $event.stopPropogation on the input box to prevent this behavior, but it didn't work as expected.

Here is the HTML code:

<body>
  <div class="container" ng-controller="BaseController">
      <div class="row" ng-click="selectedDiv=!selectedDiv" ng-class="{'colorDiv':selectedDiv}">
          <input placeholder="enter text" ng-mousedown="$event.stopPropagation()">
      </div>
  </div>
</body>

And the controller:

 app.controller('BaseController', function($scope) {
  $scope.selectedDiv=true;
});

CSS styling:

 .row{
  width:250px;
  height:200px;
  border:1px solid grey;
}
.colorDiv{
  border:1px solid red;
}

Check out the DEMO for reference.

Any assistance with resolving this issue would be greatly appreciated.

Answer №1

In order to prevent the click event from propagating up, you need to stop it explicitly on the input box. You can achieve this by using ng-click instead of ng-mousedown (mousedown will only be triggered when hovering over the input box).

ng-click="$event.stopPropagation();"

Check out the Plunker for more information.

Answer №2

Your current configuration begins in the chosen state, transitioning to the unselected state upon clicking the div.

app.controller('BaseController', function($scope) {
    $scope.selectedDiv=true;
});

Update the initial value of $scope.selectedDiv = true;

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

AngularJS: Sending form data to an external server results in an error due to restricted URI access

I am currently diving into the world of AngularJs and putting effort into mastering it. In this process, I've created a demo application that attempts to send form data to a localhost site. The code for this endeavor is provided below. index.html &l ...

How to extract dynamic content efficiently by combining Selenium and Scrapy for multiple initial URLs

I have been assigned the task of developing a web scraper for a property website where the data will be collected and stored for future analysis. The website is a national platform that requires users to select a region before displaying any results. In ...

Angular's end-to-end testing capabilities for backend systems

Is it possible to utilize Angular's e2e framework for testing web services and conducting database validations, essentially for backend testing, or is its primary function limited to front end UI testing? ...

The $.Get method does not retain its value within an each() loop

When using the jQuery each() method on a DropDown select, I iterate through an li element. However, my $.get() function takes time to fetch data from the server, so I use a loading image that toggles visibility. The issue is that the each() method does not ...

Tips for bringing in an npm package in JavaScript stimulus

Looking to utilize the imageToZ64() function within the zpl-image module. After installing it with: npm install zpl-image I attempted importing it using: import './../../../node_modules/zpl-image'; However, when trying to use the function like ...

steps to iterate through an array or object in javascript

Hello, I am facing an issue while trying to loop through an array or object. Can someone help me out? Are arrays and objects different when it comes to using foreach? function fetchData() { fetch("https://covid-193.p.rapidapi.com/statistics", { ...

Activate a dropdown menu following the selection of a date on a calendar input using vue.js

What I need to do is have two select fields, one for 'days' and the other for 'hours'. When a day is selected, the user should then be able to choose between two available time slots. If they choose day two, the available time slots sh ...

Sending Data Between Web Applications in JavaScript

Currently developing a take-away application using AppLab, which uses JavaScript. Due to the limitations of modifying HTML code in AppLab, I had to utilize an external web app for the checkout process (unable to integrate PayPal buttons in AppLab). When th ...

Triggering a JQuery slider event on each individual slider handle within the range

Can events be triggered based on the movement of individual slider handles? I am curious because I need to dynamically update a datepicker depending on which handle is moved. However, I'm unsure if there is a way to: Specify an event for a specifi ...

Error encountered: Unable to reference Vue as it has not been defined while importing an external JavaScript file

Currently, I am implementing a package called https://github.com/hartwork/vue-tristate-checkbox within my Vue.js component by adding it through the command: yarn add hartwork/vue-tristate-checkbox. In my Vue.js component, the package is imported in the fo ...

The $(document).ready function may not be compatible with Internet Explorer

I have a page with two links - one for registering and one for logging in. Currently, the register link is the most important. When clicked, it loads a .tpl file using jQuery's load function. Within this tpl file, I include a new JavaScript file usin ...

Executing a function from a parent controller within its own context

I am facing an issue where I want the parent controller's function getDataInParent to be called within the context of the parent's controller itself. For example: The child directive is correctly configured like this within the parent directive ...

Module child-process not found

Why is it that when I try to run "require('child-process')" in the node shell, I receive an error saying "Cannot find module 'child-process'"? It seems like "child-process" should be a default library in Node. Any insights on what could ...

Is there a way to create a function in JavaScript that eliminates duplicate Objects within an Array of Objects?

Currently, I'm working on a function to store details of a couch in a JS object with 3 properties locally. The properties include: An ID (obtained from the product URL using a function) A color (retrieved through an event listener) A quantity ...

After upgrading from Vuetify version 1.5 to 2.0.18, an issue arises with modules not being found

I encountered the following error: module not found error To address this issue, I took the following steps: Commented out import 'vuetify/src/stylus/main.styl' in the src/plugins/vuetify.js file. Added import 'vuetify/src/styles/main. ...

Mastering asynchronous function handling in Node.js

I'm currently experiencing an issue with printing two statements using two functions var mongoose = require( 'mongoose' ); var_show_test = mongoose.model( 'test' ); exports.showTest = function(req,res) { var jsonString = []; ...

Switching a jQuery AJAX Response

Currently, I am utilizing an AJAX function to retrieve and display specific categorical posts when a corresponding button is clicked: <script> // Brochure AJAX function term_ajax_get(termID) { jQuery("#loading-animation").show(); ...

I am experiencing some difficulty with the GetServerDate using the JSON protocol in JQuery; it's

I am facing an issue while trying to execute a basic ajax call to fetch data from a file on a server. Even though I can access the file via the web browser and have diligently followed tutorials related to this topic, I have hit a dead end. Here is the sn ...

I seem to be having trouble getting innerHTML to function properly

Whenever I attempt to showcase HTML code from a DIV element, the innerHTML function fails to retrieve its contents: <div id="container"> <tr> <td style="background-color: #ffffff;">TEST</td> </tr> </div> ...

Transferring an array from JavaScript to PHP, encountering an issue with determining the length

I'm having an issue passing an array from my .js file to a PHP file. In JavaScript, the array is structured as follows: theBlock[0 - 79] with color, x, and y values. For example, theBlock[10].color or theBlock[79].x The data is sent using the follow ...