Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created July 24, 2013 10:17
Show Gist options
  • Select an option

  • Save csharpforevermore/6069427 to your computer and use it in GitHub Desktop.

Select an option

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

aly14 commented Mar 31, 2019

Copy link
Copy Markdown

you are unbelievable.

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