Home > DeveloperSection > Forums > How to get the clicked menu details
john rob

Total Post:108

Points:756
Posted on    January-20-2015 9:55 PM

 JavaScript ASP.Net  JQuery  CSS 
Ratings:


 1 Reply(s)
 551  View(s)
Rate this:

i have jquery menu like

<ul id="fileMenu">

    <li>Refresh</li>

    <li>-</li>

    <li>Exit</li>

</ul>

<ul  id="editMenu">

    <li>Add</li>

    <li>Edit</li>

    <li>Delete</li>

</ul>

i got the way to get click event on child menu items like

  $('#fileMenu').on('click', 'li', function () {

            alert("Hello"); // Or make($(this)); if you still want that extra function

        });

But, how to find out the particular menu option, i.e user clicked on Open, Exit, Edit, delete etc...



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-20-2015 10:35 PM

Use clicked element context this to create jquery selector along with .text() to get the text in it.

You will also need to add other parent ul selector(like #editMenu) to target their elements as well :

$('#fileMenu,#editMenu').on('click', 'li', function () {

        var currenttext=$(this).text();

        alert(currenttext);

        if(currenttext=="Add"){

            //perform Add

        }else if(currenttext=="Delete"){

            //perform delete

        }else{

            //perform edit

        }   

    });


Don't want to miss updates? Please click the below button!

Follow MindStick