JavaScript how to stop parent request if clicked child angular2

I have similar code like below and I want If I clicked in Child Div then Parent Div click event should not trigger.

<div class="parentDiv" (click)="parentDiv()">
   <div class="childDiv" (click)="childDiv()">Child Container</div>
</div>

When I am clicking on "childDiv" so first it triggers "parentDiv()" event and then "childDiv()" event.

Can you please help me to resolve it?

Thankyou in advance

Answer:1

Use event.stopPropagation(); in the function attached to the .childDiv

In Javascript there is something called Event Bubbling; when an event fires for one element it fires for all of it's parent elements as well.

Heres a code snippet displaying the code needed

document.getElementById("parentDiv").addEventListener("click", function (e){
  alert('parentDiv clicked');
});

document.getElementById("childDiv").addEventListener("click", function (e){
  e.stopPropagation();
  alert('childDiv clicked');
});
<div id="parentDiv">
  Parent Container
   <div id="childDiv">Child Container</div>
</div>
Answer:2

I have the following code: Html <div ng-controller="MyCtrl"> {{message}}! <button ng-click="changeMessage()">change Message</button> </div> AngularJs var myApp = ...

I have the following code: Html <div ng-controller="MyCtrl"> {{message}}! <button ng-click="changeMessage()">change Message</button> </div> AngularJs var myApp = ...

  1. angularjs uncaught referenceerror require is not defined
  2. angularjs uncaught referenceerror is not defined
  3. angularjs uncaught referenceerror angular is not defined
  4. angularjs uncaught referenceerror exports is not defined
  5. angularjs uncaught referenceerror $filter is not defined
  6. angularjs uncaught referenceerror moment is not defined

I want to pass an Id when I open a model from bootstrap. I have a table and want to click on the row to do this. I am using master-pages and I am loading the jquery and bootstrap at the end of the ...

I want to pass an Id when I open a model from bootstrap. I have a table and want to click on the row to do this. I am using master-pages and I am loading the jquery and bootstrap at the end of the ...

Having a weird issue, on Windows 10 in the screen settings on some laptops the default value (the recommended) is 125% so when opening a web page everything is to big because the page was build for ...

Having a weird issue, on Windows 10 in the screen settings on some laptops the default value (the recommended) is 125% so when opening a web page everything is to big because the page was build for ...

  1. windows screen scale
  2. windows 10 screen scale
  3. windows scale screen size
  4. windows 7 screen scale
  5. windows get screen scale
  6. windows 10 scale screen size
  7. windows 10 change screen scale
  8. windows 7 scale screen resolution
  9. windows xp scale screen
  10. windows 10 lock screen scale
  11. windows 10 adjust screen scale
  12. windows 10 full screen scale
  13. windows 10 grayscale screen
  14. windows 10 qt_auto_screen_scale_factor

Has anyone implemented sending and receiving signals with opentok-react https://github.com/aiham/opentok-react? I can't find even a simple example on how to do it in React using opentok-react.

Has anyone implemented sending and receiving signals with opentok-react https://github.com/aiham/opentok-react? I can't find even a simple example on how to do it in React using opentok-react.