Okay, I am not sure if this has been asked, exactly how I did, but sorry if yes.
Basically, I have 10 items in a list.
By running this query:
public function get10items()
{
$this->query = $this->pdo->prepare("SELECT * FROM items LIMIT 10");
$this->query->execute();
while ($row = $this->query->fetch(PDO::FETCH_ASSOC))
{
echo '<li id="'.$row['id'].'">'.$row['name'].'</li><br />';
}
}
This will list 10 items from the database into '<ul>'. This also will set an id to each item, with it's own number, like in the database.
Now, with jquery, I want the jquery to find the ID number of the clicked item.
For example our list:
Hello! [id55]
Hai! [id66]
I clicked on item 'Hello!'. How can I find out the ID of it upon click using jquery and then use it for future use? For example, sending ajax query, with that id, etc?
<ul class="list">
<?php echo $class->get10items(); ?>
</ul>
So basically I can use this:
$(".list").on("click", "li", function() {
$.post("ajax.php", { get : this.id }, function() {
blablabla
});
});
Is that correct?