Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created July 24, 2013 10:17
Show Gist options
  • Save csharpforevermore/6069427 to your computer and use it in GitHub Desktop.
Save csharpforevermore/6069427 to your computer and use it in GitHub Desktop.
In a HTML unordered list, get the list item that was clicked (UL > LI) Code copied from http://stackoverflow.com/questions/3545341/jquery-get-the-id-value-of-li-after-click-function
$("ul.nav li").click(function () {
alert(this.id); // id of clicked li by directly accessing DOMElement property
alert($(this).attr('id')); // jQuery's .attr() method, same but more verbose
alert($(this).html()); // gets innerHTML of clicked li
alert($(this).text()); // gets text contents of clicked li
});
@aly14
Copy link

aly14 commented Mar 31, 2019

you are unbelievable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment