javascript - adding onclick event in xml result -
this main html page.
<html> <head> </head> <body> <div class="categories"> <ul></ul> </div> <script src="script/jquery-1.11.3.min.js"></script> <script src="script/myscript.js" type="text/javascript"></script> </body> </html> this xml page
<categoriesroot> <categories> <categoryid>1</categoryid> <categoryname>beverages</categoryname> <description>soft drinks, coffees, teas, beer, , ale</description> </categories> </categoriesroot> and js page
$.ajax({ url:'categories.xml', datatype:'xml', success: function(data){ $(data).find('categoriesroot categories').each(function(){ var name = $(this).find('categoryname').text(); $('.categories ul').append( $('<li/>',{ text: name }) ); }); }, error: function(){ $('.categories').text('failed'); } }); i can read xml file in main page, want is, when click categoryname beverages, display description(soft drinks, coffees, teas, beer, , ale) on right of main page. new html,please help!!
i share answer gave in post, can you:
how send content of node in xml page using php?
greetings
edition
i put sample code on next jsfidle sample. code simple. work follow:
- you call ajax request xml (
line 30). - in response function (
line 33), call function build menu. - into build function, categories (
line 9). - next, iterate on categories , build list items (
line 11 line 17). - and finally, list event handler (
line 27) catch click event on anchor tag list.
Comments
Post a Comment