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:

  1. you call ajax request xml (line 30).
  2. in response function (line 33), call function build menu.
  3. into build function, categories (line 9).
  4. next, iterate on categories , build list items (line 11 line 17).
  5. and finally, list event handler (line 27) catch click event on anchor tag list.

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -