I have the following HTML content


<input id="btnHighlight" type="button" value="Highlight"/>

When the user clicks the Highlight button, the program should change the colour of a particular list item, let's say the third list item to blue colour.

I know that every list item has its own unique index. But how can I access it directly using jQuery?

1 Answers

To select the third li element, do this:


The eq accepts an index that identifies the position of an element in a set and it selects the element corresponding to that index number. The first element will have the index number 0, and so on.

  $(document).ready(function() {
    $("#btnHighlight").click(function() {

  .highlighted { color:blue; }