Saturday 19 July 2014

How to add dynamic li to UL in jquery

How to add dynamic li to UL in jquery

jQurey Add dynamic li to UL

li adding new attribute jquery

Add Dynamic  property to li
<div>
<ul id="MyID"> </ul>
</div>
<script>
var arr = ["1","2","3"];
jQuery.each(arr, function (i, val) {
if (val.length) {
$('<li />', { html: i }).appendTo('ul.MyID')
}
$("ul.MyID li").each(function () {
$(this).attr("class", "MyClass");
$(this).attr("CustomProperty", "Text");
$(this).attr("data", "dynamicValue");
}
});
</script>