Javascript button not responding when clicked

kampias

I am attempting to use listjs in a django project i am making. But even when running a snippet taken from the documentation, django refused to run it properly. Take this pen for example. I copy this and put it in my html template. The template now has the following

<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
        <script type="text/javascript">
var options = {
  valueNames: [ 'name', 'born' ]
};

var userList = new List('users', options);
    </script>

<div id="users">
  <input class="search" placeholder="Search" />
  <button class="sort" data-sort="name">
    Sort by name
  </button>

  <ul class="list">
    <li>
      <h3 class="name">Jonny Stromberg</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Jonas Arnklint</h3>
      <p class="born">1985</p>
    </li>
    <li>
      <h3 class="name">Martina Elm</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Gustaf Lindqvist</h3>
      <p class="born">1983</p>
    </li>
  </ul>

</div>

Result is the page loads fine with no errors in the console but the button or the search do not work at all. I think it is something obvious i am missing here but cant seem to track it.

kostans3k

Try loading scripts at the end of your snippet. listjs library is expecting DOM to be loaded before you can create new List.

<div id="users">
  <input class="search" placeholder="Search" />
  <button class="sort" data-sort="name">
    Sort by name
  </button>

  <ul class="list">
    <li>
      <h3 class="name">Jonny Stromberg</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Jonas Arnklint</h3>
      <p class="born">1985</p>
    </li>
    <li>
      <h3 class="name">Martina Elm</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Gustaf Lindqvist</h3>
      <p class="born">1983</p>
    </li>
  </ul>
</div>

<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>

<script type="text/javascript">

var options = {
  valueNames: [ 'name', 'born' ]
};

var userList = new List('users', options);

</script>

Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.

En caso de infracción, por favor [email protected] Eliminar

Editado en
0

Déjame decir algunas palabras

0Comentarios
Iniciar sesiónRevisión de participación posterior

Artículos relacionados

how to show elements when button was clicked in JavaScript

Javascript - When a button is clicked the CSS property toggle after second click

Show Loader when a button is clicked

Remove row when button is clicked

Replace marker when button clicked

How to change the color of correct answer using JavaScript when check answer button clicked

how to focus a button when a textbox is clicked

Display a Toast when a button is clicked frequently

Button when clicked, the expected result is not achieved

SwiftUI round button deforms when clicked

Ask for permission when clicked on download button

angularjs - keep focus on input when clicked on a button

Change focus color when button clicked

Creating a window and hiding it when close button is clicked

How to change image when a button is clicked on Expo?

Show next question when next button is clicked

How to Toggle Classname in ReactJS when button is Clicked?

show details when user clicked selected button

Blazor: Call a server method when a button is clicked?

How to display a table when a button is clicked?

Having background on button when clicked on but not hovering vuejs

How to trigger a download when an HTML button is clicked

Create a +1 Animation when button is clicked

How to remove options when clicked on a button

Getting radio button value when button is clicked is not working angularjs

Javascript onclick how to undo when clicked again

Trigger an event when next month button clicked on fullcalendar not working

Show a returned object on a div when button is clicked using React

Add a dynamic button and specify a method when it's getting clicked

TOP Lista

CalienteEtiquetas

Archivo