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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -