0

This is the button. Imagine button with text B2C01 and next to it svg that works as close. when I click to this image the button disappears but simultaneously it triggers buttons function which does other things and it interferes with my code. how can I stop it from executing when clicking image?

    <button onclick="clickcustomer(this.id)" 
    id="addedprivatecustomerbutton1"
    class="addedprivatecustomerbutton displaynone" type="button" name="button">B2C01
    <img class="removeaddedcustomerbutton" id="addedprivatecustomersvgsvg1" 
    src="img\removeaddedcustomerbutton.svg"
    alt="" onclick="removeprivatecustomer(this.id)"> </button>
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
OgLuka
  • 19
  • 6
  • Or [How to have click event ONLY fire on parent DIV, not children?](https://stackoverflow.com/q/9183381/215552) if you read jQuery. – Heretic Monkey Aug 28 '21 at 19:03

2 Answers2

0

Your HTML would be,

        <button onclick="clickcustomer()" 
        id="addedprivatecustomerbutton1"
        class="addedprivatecustomerbutton displaynone" type="button" name="button">B2C01
        <img class="removeaddedcustomerbutton" id="addedprivatecustomersvgsvg1" 
        src="img\removeaddedcustomerbutton.svg"
        alt="" onclick="removeprivatecustomer(event)"> </button>

and JS would be,

  removeprivatecustomer(e){
    console.log("removeprivatecustomer")
    e.stopPropagation();
    console.log("removeprivatecustomer after stopPropagation")
  }

  clickcustomer(){
    console.log("clickcustomer")
  }
-1
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; 
charger=utf-8" />
    <meta name="" content="">
   <title></title>
  </head>
  <body>

 <button id="btn" onclick="stack_fn(this)">
   <img id="img" src="stack.png" alt="stack" 
onclick="stack_fn(this)">
 </button>

 <script type="text/javascript" charset="utf-8">
  function stack_fn(elm)
  {
     if(elm.id === "img")
     alert(elm);
   }
 </script>
  </body>
</html>