0

I have an infowindow in a google map like so,

var content = '<div id="link"><input type="button" value="Report this light" id="reportBtn"/></div>';

i am using jquery mobile to bind a 'click' event when the infowindow pops open on the map but it doens't fire, my code:

$(document).on('pageinit', function() {
 $('#reportBtn').on('click', function() {
     alert('it works');
 });
});

1 Answer 1

2

You need to use event delegation. Try

$(document).on('pageinit', function() {
    $(document).on('click', '#reportBtn', function() {
        alert('it works');
    });
});

Instead of document you can use nearest static element that is a parent to <div id="link">.

$('#nearestparent').on('click', '#reportBtn', function() {...});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.