JS beginner, sorry
How can could I make it so that every button that has the id "#popit" to open the same popup box?
I'm using bPopup
With this code there is only one button on the site which does open the popup
;(function($) {
$(function() {
$('#my-button').bind('click', function(e) {
e.preventDefault();
$('#element_to_pop_up').bPopup();
});
});
})(jQuery);
/ - there are 3 buttons with the same id, but only the first one opens the popup box, anyway I could make it so that every single button to open the same popupbox?
JS beginner, sorry
How can could I make it so that every button that has the id "#popit" to open the same popup box?
I'm using bPopup
With this code there is only one button on the site which does open the popup
;(function($) {
$(function() {
$('#my-button').bind('click', function(e) {
e.preventDefault();
$('#element_to_pop_up').bPopup();
});
});
})(jQuery);
http://jsfiddle.net/yg5so25s/ - there are 3 buttons with the same id, but only the first one opens the popup box, anyway I could make it so that every single button to open the same popupbox?
Share Improve this question edited Dec 12, 2014 at 9:44 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Dec 12, 2014 at 9:41 commoncommon 1011 gold badge2 silver badges9 bronze badges 2- 3 You should use classes when you want to identify multiple elements. id should be unique – Hacketo Commented Dec 12, 2014 at 9:43
- 3 By definition, an id must be unique – pistou Commented Dec 12, 2014 at 9:44
2 Answers
Reset to default 12id
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
use common class for all buttons
$('.commonClass').bind('click', function(e) {
e.preventDefault();
$('#element_to_pop_up').bPopup();
});
DEMO