how do i get the value of the button clicked?

Assuming the rendered html looks like this:

<div class="dropdown-content" id="account">
    <a href="/layout">1</a>
    <a href="/layout2">2</a>
</div>

In your code you handle a click on the div and not on the a element.

So all you need is this:

$("#account > a").click(function(e){
     var $a = $(this);
    // $a is the "a element"
    alert($a.text());
    
    // to prevent browser going to the link in href call 
    e.preventDefault();    
});

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top