You can use SharePoint 2010's JavaScript client object model to access SharePoint list/library data from JavaScript without having to parse rendered HTML.
In SharePoint 2010, to run some JavaScript on a page (without messing around with SharePoint Designer or Visual Studio), you can:
- Place a combination of HTML and JavaScript in a text file
- Save the text file to a document library on your site
- Add a Content Editor web part to a page where you want the HTML/JavaScript to display/execute
- Edit the properties of the web part
- In the Content Link property you can paste in the path to your text file
The embedded JavaScript will then run when that web part loads, and the HTML will display wherever you place it. (Note that SharePoint 2013 introduced the Script Editor web part, simplifying this process somewhat.)
As a reference for getting started with the JavaScript client object model, here's a barebones example:
<ul id="PointList"></ul>
<script>
var pointList = document.getElementById("PointList");
ExecuteOrDelayUntilScriptLoaded(loadListData,"SP.JS");
function loadListData(){
var clientContext = new SP.ClientContext();
// Replace "Example List" with your list's title below:
var list = clientContext.get_web().get_lists().getByTitle("Example List");
var camlQuery = new SP.CamlQuery();
// use a CAML query to retrieve a set of list items:
camlQuery.set_viewXml(
'<View><Query>'+
'<Where>'+
// '<BeginsWith>'+
// '<FieldRef Name=\'Title\' /><Value Type=\'Text\'>A</Value>'+
// '</BeginsWith>'+
'</Where>'+
'<OrderBy>'+
// '<FieldRef Name=\'Modified\' />'+
'</OrderBy>'+
'</Query></View>');
var items = list.getItems(camlQuery);
clientContext.load(items);
clientContext.executeQueryAsync(
/* code to run on success: */
Function.createDelegate(this,
function(){
var item, itemEnumerator = items.getEnumerator();
while(itemEnumerator.moveNext()){
item = itemEnumerator.get_current();
// Replace "Title" and "Points" with the
// internal names of your fields below:
addHTML(item.get_item("Title"), item.get_item("Points"));
}
}
),
/* code to run on error: */
Function.createDelegate(this,
function(sender,args){
alert(args.get_message());
}
)
);
}
function addHTML(name, points){
var li = document.createElement("li"),
nameSpan = document.createElement("span"),
pointSpan = document.createElement("span");
pointList.appendChild(li);
li.appendChild(nameSpan);
li.appendChild(pointSpan);
nameSpan.innerHTML = name;
pointSpan.innerHTML = points;
}
</script>
I commented out the inner elements of the Where and OrderBy clauses in the CAML query so that it'll just grab everything in the default order, but you can still see the general format. By changing that CAML query, you can grab a filtered subset of items and/or get them in a particular order. (For more details on CAML syntax, check out this answer.)
Here are a few good JavaScript references from Microsoft for further research: