vendredi 30 octobre 2020

How to add && to onclick and if function in javascript? Thanks alot

So I have a code that looks like this

<button id="p1" onclick="p();" >p1</button>
<button id="p2" onclick="p();" >p2</button>
<p id="p3">2</p>

And then I would like to make a function that goes

function p(e){

    var p= document.getElementById("p3").innerHTML;

    if('p1'==e && p!=2){alert('yes');}

    if('p2'==e && p==2){alert('no');}

}

I don't know why it's just not working.

How to use if and && and onclick together in this case?

Please guide me further and in javascript only.

Aucun commentaire:

Enregistrer un commentaire