0

I have this HTML and JS/jQuery code:

$(document).ready(function() {
$("#livesearch").on("click",  ".searchres", function(event){
    console.log('clicked');
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="livesearch">
  <?php foreach($data as $i){?>
    <li class="searchres"><?php echo $i["name"];?></li>
    <?php } ?>
</ul>

This is part of a dropdown list that appears after an input form is being populated.

I would like to press on one of the dropdown lists .searchres and just print to console as a test.

This is, however, not printing on console. What am I doing wrong?

Details

At the start of my php file I have this code snippet that creates a 'livesearch' object which connects to my database.

<?php
  require_once('livesearch.php');
  $livesearch = new livesearch();
  $data = null;
  
?>

I am declaring $data=null here because I do not want any database fields to show at loading time. could this be the issue that is making livesearch Id non-existant on load?

Community
  • 1
  • 1
user7331538
  • 1,258
  • 1
  • 9
  • 31

0 Answers0