I'm trying to parse my data from an xml file now and print it out on the page based on date from my existing code. I have that working, with each item formatted the same way on the page What I'd like to do now is alter it a bit to make the most recent (the item listed on the top of the page) formatted differently and the rest of them as it is now. Something like - (if 1st <li> then build html like this else build html like that) I hope this makes sense.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<books>
<book title="CSS Mastery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/css.jpg">
<description>
08/01/2010 - Content
</description>
</book>
<book title="Professional ASP.NET" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/asp.jpg">
<description>
08/02/2010 - Content
</description>
</book>
<book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg">
<description>
08/03/2010 - Content
</description>
</book>
<book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg">
<description>
08/04/2010 - Content
</description>
</book>
<book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg">
<description>
08/05/2010 - Content
</description>
</book>
</books>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Load XML With jQuery</title>
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function()
{
/*Gets current date*/
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var date = new Date();
/*var curr_date = d.getDate();*/
var curr_date = 3;
var curr_month = date.getMonth();
var curr_year = date.getFullYear();
$.get('myData.xml', function(d){
/* $('body').append('<h1> Title</h1>');*/
$('#col-a').append('<ul id="tips"/>');
$(d).find('book').each(function(){
var $book = $(this);
var title = $book.attr("title");
var description = $book.find('description').text();
var imageurl = $book.attr('imageurl');
var html = '<li class="tipItem" style="list-style:none;display: none; li">';
html += '<img class="bookImage" alt="" src="' + imageurl + '" /> ';
html += '<p class="title">' + title + '</p>';
html += '<p> ' + description + '</p>' ;
html += '</li>';
$('ul').append($(html));
});
var tips = $('#tips .tipItem');
tips.each(function(i) {
if (curr_month == 8 && curr_date <= i){
$(this).hide();
} else {
$(this).show();
}
});
tips = $.makeArray(tips);
tips.reverse();
$(tips).appendTo(document.getElementById('tips')
);
});
});
</script>
</head>
<body>
<div id="col-a"></div>
</body>
</html>
Bookmarks