javascript - JQuery - on('click') doesn't work with map area -




i'm writing code .html() has html map area (it's workaround enable/disable map area)

i can work live event (works on click on image) doesn't work map area. can't found hint this, researched , test several ways no-result.

my var html:

 var mapimage = '<map name="image-map"><area target="" href="#" alt="" title="" id="s" coords="55,109,130,220" shape="rect"><area target="" href="#" alt="" title="" id="b" coords="135,108,205,222" shape="rect"><area href="#" target="" alt="" title="" id="w" coords="213,109,296,223" shape="rect"><area href="#" target="" alt="" title="" id="n" coords="303,91,387,225" shape="rect"><area href="#" target="" alt="" title="" id="r" coords="58,223,131,323" shape="rect"><area href="#" target="" alt="" title="" id="l" coords="133,224,210,322" shape="rect"><area href="#" target="" alt="" title="" id="t" coords="215,225,293,324" shape="rect"><area href="#" target="" alt="" title="" id="g" coords="303,229,387,324" shape="rect"><area href="#" target="" alt="" title="" id="p" coords="540,96,686,217" shape="rect"><area href="#" target="" alt="" title="" id="b" coords="515,229,583,320" shape="rect"><area href="#" target="" alt="" title="" id="k" coords="594,225,679,322" shape="rect"><area href="#" target="" alt="" title="" id="x" coords="7,350,4,298,50,304,52,326,392,327,391,301,508,300,509,323,685,325,684,299,735,299,757,291,756,354" shape="poly"></map>';             var mainimage = '<img id="panel" src="imgs/main1.png" width="760" height="360" class="img-responsive img-thumbnail" alt="responsive image" usemap="#image-map">'; 

my last attempt of event (go basics alert here):

    $("#b").on('click', function (e) {         e.preventdefault();         alert('test');     }); 

not useful code use write first appereance of html:

  $("#panel").on('click', function () {             switch (panel) {                 case 0:                     $("#maindiv").html(mainimage + mapimage).promise().done(function () {                         $('#panel').attr("src", "imgs/day_off.png");                         panel = 1;                     });;                      break;             }         }); 

of course inside dom (on document ready).

where error? hint or comment or answer preciated. testing in lastest mozilla, , latest chrome. works if not write html dinamically.

setting click binding on page load element doesn't exist yet won't work. won't register because element doesn't exist!

you need register event handler on element exist @ page load, , parent on dynamically created element.

see answer format/how to: https://stackoverflow.com/a/1207393/5173105

if #panel exists @ page load , contains #b element, suggested solution:

$("#panel").on('click', '#b', function (e) {     e.preventdefault();     alert('test'); }); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -