Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13570 closed bug (notabug)

error in the description: addClass

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:

Description

http://api.jquery.com/addClass/

<script type="text/javascript">
$(document).ready(function(){
   $("ul li:last").addClass(function(index) {
      return "item-" + index;
   });
	
   $("ul li").each(function(){
      alert($(this).attr('class'));
   });
});
</script>

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>

"Given an unordered list with five <li> elements, this example adds the class "item-4" to the last <li>."

not "item-4" -> "item-0"

Change History (2)

comment:1 Changed 10 years ago by m_gol

This is expected, indexes go from 0. What did you expect? Also, if you think that something is broken, don't just paste code here but go to jsfiddle.net and create a test case that clearly states what you expect and demonstrates that it doesn't to that.

comment:2 Changed 10 years ago by timmywil

Resolution: notabug
Status: newclosed
Note: See TracTickets for help on using tickets.