How to Have Multiple Buttons of Same Id Value and When Click on Any Button the Pop-Up Should Come

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 required inputs. Then code can be simplified to:

    $(document).on("click", ".button", function() {
    $("#poper").dialog("open");
    });
  • Update. With inputs 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



Leave a reply



Submit