Marco Dinatsoli Marco Dinatsoli - 17 days ago 8
Javascript Question

jquery get the text inside <li>

I have this div

<div class="RestauranstSection">
<label>
Restaurant:
</label>
<input type="text"/>
<input type="button" value="Search"/>
<ul>
<?php while ($row = $restaurants->fetch()) {
?>
<li id="<?php echo $row['ID']; ?>">
<?php echo $row['name']; ?>
</li>
<?php } ?>
</ul>
</div>


I want when press on any
li
elements to alert its text,

$(".RestauranstSection").on('click','li',function (){});


how please?

Answer
$(".RestauranstSection").on('click','li',function (){
    alert($(this).text());
});