Jump to content

Links not working on dynamic page


Go to solution Solved by Digger,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/317510-links-not-working-on-dynamic-page/
Share on other sites

Probably because of the sequence of events. I suspect it is ...

  1. page loads
  2. <script> is run
  3. 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..

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.