Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>event.target will give you the element that triggered the event, or $(this). So for instance you can do something like </p> <pre><code> $("li").click(function(event) { var clickedItemID = event.target.id; //your snipped to affect page 2 goes here .... }); </code></pre> <p>depending on what else is on the page you probably want to target the event better that just attaching to every li obviously.</p> <p>EDIT</p> <p>You may be able to get away without a switch/case statement if you can modify content based on appending the ID that you receive from the event to some other element. For example if when clicked you are changing an image on the other page you can use something like</p> <pre><code>$("li").click(function(e) { var list_id = $(this).attr('id'); $('#page2-image').attr('src', list_id + '.jpeg'); }); </code></pre> <p>If you can get away with this approach it is better than switch/case as the function does not need to be edited each time you add/remove options. BTW - the above is a rough example only and doesn't account for any passing of data between jquery mobile pages.</p> <p>The alternative would be something like</p> <pre><code>$("li").click(function(e) { var list_id = $(this).attr('id'); switch(list_id) { case "A": //execute code block 1 break; case "B": //execute code block 2 break; case "C": //execute code block 2 break; case "D": //execute code block 2 break; default: //code to be executed if case not covered above } }); </code></pre> <p>Which as you can see requires a lot more code.</p> <p>Glen</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload