skip to Main Content

I changed the jQuery version from 3.6.0 to 3.6.3 and I get an error when I use the load function.

I have the below code

$(document).ready(function() {
   $('.nav, #menu').click(function(e) {
    e.preventDefault();
    $('#content').load($(this).attr('href'));
    });
});

and I get the below error

TypeError: Cannot read properties of undefined (reading ‘indexOf’)
at jQuery.fn.load (jquery-3.6.3.js:10473:13)
at HTMLUListElement. (dashboard.php:64:19)
at HTMLUListElement.dispatch (jquery-3.6.3.js:5494:27)
at elemData.handle (jquery-3.6.3.js:5298:28)

If I change the jQuery version to 3.6.0 the error disappears. If I change the version of jQuery to 3.6.1, 3.6.2, or 3.6.3 I get the above error.

Is anything wrong with my code?

I tried different versions of jquery and I get the same error.

2

Answers


  1. Chosen as BEST ANSWER

    The element are links as you can see below

    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="collapse" aria-expanded="false" data-bs-target="#submenu-3" aria-controls="submenu-3">Practice</a>
      <div id="submenu-3" class="collapse">
        <ul class="nav nav-small flex-column">
    
        <li class="nav-item">
           <a id="menu" class="nav-link" href="practise.php">Practice</a>
          </li>
          <li class="nav-item">
            <a id="menu" class="nav-link" href="statistics.php">Statistics</a>
          </li>
    
        </ul>
      </div>
    </li>
    

  2. Without seeing your html its a guess, but you probably fire the event through elements that arent links. Try changing it to:

    $(function() {
       $('.nav a, #menu a').click(function(event) {
          event.preventDefault();
          $('#content').load($(this).attr('href'));
       });
    });
    

    Or, to be super sure:

    $(function() {
       $('.nav *[href], #menu *[href]').click(function(event) {
          event.preventDefault();
          $('#content').load($(this).attr('href'));
       });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search