I've been browsing through stackoverflow for a while and have not found an answer that suits my problem - I want to load in a certain part of my xml file when I click a button. I want to load parts of my xml file into 'contents' div.
This is my HTML Code :
<div>
<input type="button" id="click"/>
<div id="content">
</div>
</div>
This is my XML :
<?xml version="1.0" encoding="utf-8"?>
<books>
<book id="jeff">
<author>Jeffrey </author>
<title>Books 1</title>
</book>
<book id="jerry">
<author>Jerry</author>
<title>Books 2</title>
</book>
<book id="jimmy">
<author>Jimmy</author>
<title>Boks 3</title>
</book>
<book id="jem">
<author>Jem</author>
<title>Books 4</title>
</book>
</books>
I have tried this (I know this is far from right - so no hate please) :
$(document).ready(function() {
$('#click').click(function(){
$.ajax({
url : 'books.xml',
dataType : 'xml',
success : parse,
});
function parse(xml){
$('#content').append($(xml).find('authour').text());
}
});
});
How would I access each authours id specification using jQuery. (Sorry if I messed up explaining it ! :) ).