I have an array of error messages: json.Errors
Is there a way that can create the following from this array using
jQuery?
<ul class="message" id="message">
<li>message1</li>
<li>message2</li>
</ul>
In the past I did something like the following code:
$.map(json.Errors, function (error) {
return error + '</br>';
}).join('');
I am not sure it helps but maybe someone knows how $.map could
be used for this.
I’d suggest:
JS Fiddle demo.
This, of course, requires a 1:1 relationship between the
lielements and thejson.Errorsarray.If you wanted to create the
lielements (rather than rely on their already being present), then I’d suggest:JS Fiddle demo.
References:
appendTo().eq().jQuery.each().text().