Digger Posted December 5, 2023 Share Posted December 5, 2023 I have a page loaded into a div <script> $(document).ready(function(){ $( "#nav-home" ).load("'.DIR.'admin/client/list" ); }); </script> `That work fine Within admin/client/list is the following <div class="dropdown btn-group"> <button class="btn btn-secondary btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action</button> <div class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenuButton" style="right:auto; left: auto;"> <a class="dropdown-item" href="#reject"><i class="fas fa-angle-right mr-2"></i> Reject / Cancel</a> <a class="dropdown-item" href="#approve"><i class="fas fa-angle-right mr-2"></i> Approve</a> <a class="dropdown-item" href="#active"><i class="fas fa-angle-right mr-2"></i> Activate</a> <a class="dropdown-item" href="#delete"><i class="fas fa-angle-right mr-2"></i> Delete</a> </div> </div> I cannot get the links to trigger with Jquery I have tried <script> $('.dropdown-item').click(function $('.dropdown-item').on('click', function $('.dropdown-item').on('click','a', function $('.dropdown-item').live('click', function $('.dropdown-item').live('click', 'a' function $('.dropdown-item').bind('click', function $('.dropdown-item').bind('click', 'a' function Nothing seems to be working so any help would be much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/ Share on other sites More sharing options...
Barand Posted December 5, 2023 Share Posted December 5, 2023 Probably because of the sequence of events. I suspect it is ... page loads <script> is run client/list is loaded Try moving the code from <script> to the ready() function after the load so that the elements are loaded before you create their event handlers.. Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/#findComment-1613337 Share on other sites More sharing options...
Digger Posted December 5, 2023 Author Share Posted December 5, 2023 The code entered isn't the exact code it was just a quick example everything is done proper <script> $(document).ready(function){ $( "#nav-home").load("'.DIR.'admin/client/list" ); /* $('.dropdown-item').click(function(){ alert('clicked'); }); Doesnt work */ /* $('.dropdown-item').on('click', function(){ alert('clicked'); }); Doesnt work */ /* $('.dropdown').on('click', 'a', function(){ alert('clicked'); }); Doesnt work */ /* $('.dropdown-item').live('click', function(){ alert('clicked'); }); Doesnt work */ /* $('.dropdown-item').live('click', 'a', function(){ alert('clicked'); }); Doesnt work */ /* $('.dropdown-item').bind('click', function(){ alert('clicked'); }); Doesnt work */ /* $('.dropdown-item').bind('click', 'a', function(){ alert('clicked'); }); Doesnt work */ }; </script> None of the above are working Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/#findComment-1613338 Share on other sites More sharing options...
Barand Posted December 5, 2023 Share Posted December 5, 2023 Have you tried my suggestion? Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/#findComment-1613339 Share on other sites More sharing options...
Digger Posted December 5, 2023 Author Share Posted December 5, 2023 Yes i tried it before I posted the question Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/#findComment-1613340 Share on other sites More sharing options...
Barand Posted December 5, 2023 Share Posted December 5, 2023 8 minutes ago, Digger said: Doesnt work Code that is commented out seldom does. Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/#findComment-1613341 Share on other sites More sharing options...
Solution Digger Posted December 5, 2023 Author Solution Share Posted December 5, 2023 $(document).ready(function(){ $( "#nav-home").load("'.DIR.'admin/client/list", function() { $(".dropdown-item").on("click", function(){ alert("clicked"); }); }); }); That worked Quote Link to comment https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/#findComment-1613342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.