开发者

js event listener on object (Google Maps)

开发者 https://www.devze.com 2023-04-01 14:34 出处:网络
The following lines of code document what I\'m trying to ac开发者_开发百科chieve. In detail, I\'m trying to attach an addListener to a DOM object. Sadly it seems that I can\'t access it.

The following lines of code document what I'm trying to ac开发者_开发百科chieve. In detail, I'm trying to attach an addListener to a DOM object. Sadly it seems that I can't access it.

var dom_obj = document.getElementById( 'dom_obj_id' );

console.log( typeof dom_obj ); // console: object

google.maps.event.addListener( dom_obj, 'click', function() {
    // the following two lines don't appear
    alert( 'Test - called from addListener' );
    console.log( dom_obj );
} );
jQuery( zoom_in ).click(
    function() {
        // works
        alert( 'Test - called via jQuery click function' );
        console.log( dom_obj );
        return false;
    }
);


Searched for hours and found the solution seconds after typing the Q...

Simple as it is: Use addDomListener instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消