javascript - Jquery .click() not working multiple button -
i want show alertbox on click button more of button id attr , work click on first button not working click on second button.
jquery;
jquery("#submit").click(function(e){ alert("message"); });
html; (repeat html per message)
<div class="reply"> <form id="vivam" method="post" onsubmit="return false;"> <textarea name="reply" placeholder="write reply here"></textarea> <p class="stdformbutton"> <button id="submit" class="btn btn-primary">reply</button> </p> </form> </div>
what solution problem? thank in advance answers.
approach 1: ids should unique, use class instead of id.
html:
<div class="reply"> <form id="vivam" method="post" onsubmit="return false;"> <textarea name="reply" placeholder="write reply here"></textarea> <p class="stdformbutton"> <button class="btn btn-primary submit">reply</button> </p> </form> </div>
js:
jquery(".submit").click(function(e){ alert("message"); });
approach 2: can use attribute value selector target element same id. breaks rule ids should unique
.and not recommend using this:
jquery("[id=submit]").on('click',function(e){ e.preventdefault(); alert("test"); });
Comments
Post a Comment