javascript - Stop event propagation for multiple inline functions JS -


i have type of code :

<button onclick="fn1();fn2();fn3()">clic</button> 

i test in fn1 , if true, don't want fn2 , fn3 called. used event.stoppropagation() in fn1 (in cross-browser manner , passing event function) others functions called anyway.

can ?

try this:

<html> <head>   <script>     function fn1() {         alert('fn1()');         return false;     }      function fn2() {         alert('fn2()');         return true;     }      function fn3() {         alert('fn3()');         window.location.assign("http://www.google.com");     }   </script> </head> <body>     <button onclick="fn1()&&fn2()&&fn3()">click</button> </body> </html> 

all functions should return boolean use logical operators && inside onclick

<button onclick="fn1()&&fn2()&&fn3()">click</button> 

as can see if fn1() returns false f2() , f3() not executed.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -