how to know which anchor link is selected

advertisements

I am building a website in which left side is restaurant name and in right side there is anchor link button.All button are produced from a single link inside a while loop.

while($dt=mysqli_fetch_array($res,MYSQLI_ASSOC))
{
<a class='morebtn hvr-rectangle-in'  href='#'>Menu!</a>
}

All anchor button is same so how to know which button is get selected so that I can display menu page for that restaurant.


Change your code to this

$i = 0;
while($dt=mysqli_fetch_array($res,MYSQLI_ASSOC))
{
    echo "<a class='morebtn hvr-rectangle-in' id = 'a_'.$i href='#'>Menu!</a>";
    $i++;
}

And then write javascript like this

<script type = "text/javascript">
$(document).ready(function(){
    $('.morebtn hvr-rectangle-in').click(function(){
          var myId = this.id;
          //alert(myId);

        });
    });
</script>

then use that id.