Build A List With Javascript Append
Solution 1:
replace your ul tag with a table
<table id='results-list'></table>
then append table headings and rows to your table with jquery.
$('#results-list').append("<tr><th>number</th><th>code</th></tr>");
$('#results-list').append("<tr><td>"+ this.number + "</td><td>" + this.code + "</td></tr>");
more info about html tables can be found here:
Solution 2:
It's better as table. here is working example with tables. just design it as you want.
Html
<divid='results-holder'><tableid='results-list'><tr><th>
number
</th><th>
code
</th></tr></table></div>
Javascript
$(document).ready(function(){
$.each(data.results, function() {
$('#results-list').append("<tr><td rel='" + this.number + "'>" + this.code + "</td><td>" + this.number + "</td></tr>");
});
});
Solution 3:
this should be done with CSS or table?
These are not mutually exclusive. <table>
is an HTML element, which like other elements you should choose if it has semantic purpose, i.e. if the element contains data that pertains to what the element stands for. Then you use CSS to make it look the way you want to.
If you have a paragraph of text that needs to be very huge, it's still a paragraph, so you put it in a <p>
and then you style it with CSS to look big. Putting it in a <h1>
element would also make it big, but that element is for titles.
If you have tabular data, like showing the contents of a database table you should use a <table>
. Then you use CSS to hide the borders.
I'd do something like this:
$.each(data.results, function(){
$('#results-list').append("<tr><td>" + this.code + "'</td><td>" + this.number + "</td></tr>");
});
And make the #results-list
a <table>
Post a Comment for "Build A List With Javascript Append"