Multiple buttons with the same #id to do the same function?
id
must be unique, you need to use class instead:
<button class="my-button">POP IT UP</button>
then you can use .
to target elements by class name:
;(function($) {
$(function() {
$('.my-button').bind('click', function(e) {
e.preventDefault();
$('#element_to_pop_up').bPopup();
});
});
})(jQuery);
Updated Fiddle
jquery pop up - same pop up, multiple buttons to launch it
If you want multiple elements to open your pop-up, why not use a class
as a selector for the click
event instead? IDs must be unique, so you can only have 1 per page. Javascript DOM selectors will only grab the 1st one on the page (even if you had 10 things with the same ID).
$('.myButtons').bind('click', function(e) {
// your code
});
Now html elements with class="myButtons"
will trigger it.
jQuery using multiple buttons of the same class to return a value
Try this
$(".remove").click(function() {
var id = $(this).attr('id'); // $(this) refers to button that was clicked
alert(id);
});
How to open one dialog- box from multiple buttons on the same html page
- You can hang click handler for all
input
inside.front
elements. Due to dynamically created elements it should be, for example
$(document).on("click", "selector", function() {})
instead of
$("selector").click(function() {})
So finally code will look like:
$(document).on("click", ".front input", function() {
$("#poper").dialog("open");
});
You can add class (for example,
.button
) for requiredinput
s. Then code can be simplified to:$(document).on("click", ".button", function() {
$("#poper").dialog("open");
});Update. With
input
s class.poperbtn
it will be$(document).on("click", ".poperbtn", function() {
$("#poper").dialog("open");
});
Javascript modal to work only if button was clicked
What solved my auto-submit issue was turning button from :
<button class="button button" id="newselect">button</button>
to:
<button class="button button" id="newselect" type="button">button</button>
Adding type="button"
Related Topics
To Get a Popup Message After Submit
Using Thymeleaf Variable in Onclick Attribute
Using Html5/Javascript to Generate and Save a File
Regex to Get String Between Curly Braces
Calculate Time Difference Between Two Date in Hh:Mm:Ss JavaScript
Pass Parameter from Input to Onclick Method
Call Function Onpress React Native
Handling Multiple Http Responses One by One in Angular 6
Check Whether an Input String Contains a Number in JavaScript
How to Check If a Textbox Is Empty Using JavaScript
Horizontal Scrollbar on Top and Bottom of Table
How to Programmatically Clear/Reset React-Select
Convert JavaScript Date Format to Yyyy-Mm-Ddthh:Mm:Ss
How to Check a Radio Button in the Table Row Based on That Column Header