Answer the question
In order to leave comments, you need to log in
How to add a click event to the Yandex Maps balloon button?
Hello, I'm trying to hang an on click event on the balloon button,
'balloonContentBody': '<input type="button" value="Выбрать" class="baloon-button">'
$.ajax({
// получаю метки и балуны
}).done(function(data){
data = JSON.parse(data);
if (data['success'] === true){
let objectManager = new ymaps.ObjectManager({
clusterize: true,
gridSize: 32,
clusterDisableClickZoom: true
});
map.geoObjects.add(objectManager);
objectManager.add(data['information']);
let layout = map.getBalloon().getLayout();
YMaps.jQuery(layout.getRootNodes()).find('.baloon-button').click(function() {
console.log('Do something...');
});
} else{
console.log(data['error']);
}
});
but i get an errormap.getBalloon is not a function
$('.baloon-button').on('click', function(){
console.log('Do something...');
});
Answer the question
In order to leave comments, you need to log in
Eugene replied in a comment
via own balloon template
let myBalloonFooterBodyLayout = ymaps.templateLayoutFactory.createClass(
'<input type="button" value="Выбрать" class="baloon-button">', {
build: function() {
myBalloonContentBodyLayout.superclass.build.call(this);
$('.baloon-button').on('click', function() {
console.log('Do something...');
});
}
});
let objectManager = new ymaps.ObjectManager({
contentFooterLayout: myBalloonFooterBodyLayout
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question