Inserting a List Element into an Ordered List
Hello all, first time poster here, new to jQuery.
I'm working on a project that requires dynamic manipulation of an ordered list -- adding and removing elements in response to the user pressing buttons. I've run in to some odd behavior. Here's my code:
HTML
- <ol id="track-list">
- <li>Static Content Here</li>
- </ol>
- <input type="button" id="add-track" value="Add Track" />
jQuery:
- $("#add-track").click(function(){
- var listEl = $("<li>Dynamic Content Here</li>");
- listEl.hide();
- $("#track-list").append(listEl);
- listEl.fadeIn();
- } );
Looks pretty straightforward, problem is when I add the new list element it does not prepend it with any number (being part of an ordered list). Now if I remove the hide and fadeIn lines (just append it), it inserts it correctly with a number before it, but I want this to look pretty being jQuery and all...
Any pointers on what I'm doing wrong? Is there a smarter way to go about this seemingly simple task?