JQuery.on () function does not work with click event

I work with MS Dynamics CRM 2013 and I face the problem that when I want to add an event handler to the "Documents" button in the navigation bar,

enter image description here

The jQuery.on () function does not work with the click event. It works great with mouseover or mouseup events, but it doesn't work with click. Here is the code I'm using:

$("#crmMasthead").on( "click", "#Node_navDocument", function(){ alert("Success!"); } );

Where:
#crmMasthead - static selector;
#Node_navDocument - id of the button "Documents", that I want to reload.

Please help me with this problem. Thank you in advance!

EDIT

Here is the html I'm dealing with:

Before the user opens the navigation bar in CRM 2013:

<body>
...
    <div id="crmMasthead" tabindex="-1">
        <div class="navStatusArea" id="navStatusArea"></div>
        <div class='navBar' id='navBar'>...</div>       
        <div class="navBarOverlay" id="navBarOverlay" style="display: none;">     </div>
    </div>
...
</body>

A user has just opened the navigation bar in CRM 2013:

<body scroll="no">
...
    <div id="crmMasthead" tabindex="-1">
        <div class="navStatusArea" id="navStatusArea"></div>
        <div class='navBar' id='navBar'></div>
Changed:<div class="navBarOverlay" id="navBarOverlay" style="display: block;"></div>
New:    <div class="navActionGroupContainer" style="">
            ...
            <a class="navActionButtonContainer navActionButton     navActionButtonDefault normal " id="Node_navDocument" role="button" title="Documents" href="javascript:;" unselectable="on" style="background-color: #555555">...</a>
            ...
        </div>

    </div>
...
</body>
+4
source share
3

, .on() click - click #Node_navDocument , event.stopImmediatePropagation(), .

...

click iframe src . , , :

enter image description here

  • (1), onclick (2);
  • onclick (2) if iframe .

(1) id #TabNode_tab0Tab, (2) - #Node_navDocument iframe - #areaDocumentFrame.

:

replaceDocumentsLink: function () {
    console.log("Function was started!");
    var listener = {};

    window.top.$("#TabNode_tab0Tab").on("mouseover", function () {
        if (window.top.$('#Node_navDocument').length)
            window.top.$('#Node_navDocument')[0].onclick = function () {
                listener = setInterval(function () {
                    if ($("#areaDocumentFrame").length) {
                        console.log("Frame was found!")
                        $("#areaDocumentFrame").attr("src", "http://www.microsoft.com/");                            
                        clearInterval(listener)
                    }
                    else
                        console.log("Frame was not found!")
                }, 250);
            }
    });  
+3

Try

jQuery(document).on('click', '#Node_navDocument', function() {
    alert("Success!");
});

jQuery('#Node_navDocument').click(function() {
    alert("Success!");
});
+1

, , , .

demo, div , .

, , :

    $("#crmMasthead").on('click', function() {
       $(this).append("<div id=\"Node_navDocument\"> B </div>");
    });

append, "#Node_navDocument", , , :

   $("#crmMasthead").on('click', "#Node_navDocument", function() {
          .......
   });

z- . , - div. .

2 html

, ( Node_navDocument). , , any preventDefault() click!

-1

Source: https://habr.com/ru/post/1530048/


All Articles