Ok so I have this HTML
structure and I need to keep appending a new li
after test3 and so on...right before the form li
. I know how to do the append logic in jquery
but how do I isolate and make sure I can keep doing it....maybe use the live function.
<td class="resources_present">
<ul>
<li><a href="http://test.com">http://test.com</a></li>
<li><a href="http://test2.com">http://test2.com</a></li>
<li><a href="http://tes3.com">http://test3.com</a></li>
<li><form method="post" id="new_resource" class="new_resource" action="/resources" accept-charset="UTF-8"><div style="margin: 0pt; padding: 0pt; display: inline;"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="BEeMlTtPiMi8mv/whQ2z757CTTOnNl0oiPpN3WdqSBg=" name="authenticity_token"></div>
<div class="field">
<input type="text" size="30" name="resource[url]" id="resource_url">
<input type="hidden" value="5" name="resource[course_id]" id="resource_course_id">
</div>
<div class="actions">
<input type="submit" value="Create" name="commit" id="resource_submit" style="display: inline;">
<img class="noShow" src="/images/spinner.gif" style="display: none;">
</div>
</form></li>
</ul>
</td>
Basically I need to find the selector to add this:
<li><a href="http://test4.com">http://test4.com</a></li> // after the
<li><a href="http://test3.com">http://test3.com</a></li> // and continue to do that with 5, 6 , 7, and so on
Many ways to do this. Here's one:
$('li:last').prev();
And to add:
$('li:last').prev().after('<li><a href="http://test4.com">http://test4.com</a></li>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With