Iterate Through Dynamic tags and populate using jquery -
i have far...
<script type="text/javascript"> $(document).ready(function () { $('ul').addclass('navmenu'); $('li').addclass('todo').html("<span class='navitemhead'></span>"); $('span.navitemhead').wrap("<a href='/my/website'></a>"); }); </script>
i have 4 names want put name tag mary,nick,matt,meg , 1,2,3,4 in span tag, final html should read.....
<li class="todo "> <a href="/register/website"><span class="navitemhead">1</span>mary</a> </li> <li class="todo "> <a href="/register/website"><span class="navitemhead">2</span>nick</a> </li> ....etc
var names = ['mary', ...]; $('li').addclass('todo').html(function (i) { return "<a href='/my/website'><span class='navitemhead'>" + (i + 1) + "</span>" + names[i] + "</a>"; });
Comments
Post a Comment