javascript - How to compare between two or more buttons in js? -


i have 2 buttons in html code. want call 1 js function (no jquery) each buttons.

the function have conditions. want know how compare between button clicked user.

example :

if (button 1 clicked) {    block  } else {    block  }

the other way make 1 function per button don't want this.

thank much.

as mentioned in comment, add parameter this know button clicked getting id.

function myfunction(elem) {       document.getelementbyid("demo").innerhtml = "id:" + elem.id;   }
<button id='1' onclick="myfunction(this)">button 1</button>  <button id='2' onclick="myfunction(this)">button 2</button>    <p id="demo"></p>


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -