Have 3 tabs where the data is coming from XML and each part has different Data - using jQuery -


so need have 3 divs. when click on each link appropriate div shown info coming xml file.

here xml file:

<dynamic_div> <div set="1">     <p>lorem ipsum dolor sit amet, consecter adipiscing elit. ut ac ipsum et metus cursus feugiat nec @ purus. in imperdiet lectus eu metus mollis nec mollis sem tincidunt.</p>     <p>vestibulum lortis est eu ante bendum convallis ornare dolor consectetur. proin gravida turpis non odio lacinia sit amet elementum justo dapibus.</p>     <p>duis eget lacus id lectus adipiscing bibendum @ ut dolor. sed laoreet leo id nunc elementum rhoncus leo bibendum.</p> </div>  <div set="2">     <image>         <name>image</name>         <source>/img/jpeg.jpg</source>         <alt>some alt info</alt>     </image> </div> <div set="3">     <links>         <title>web links</title>         <link>             <name>site 1</name>             <url>http://www.w3.org</url>         </link>         <link>             <name>site 2</name>             <url>http://www.site.com</url>         </link>         <link>             <name>site 3</name>             <url>http://www.site.net</url>         </link>         <link>             <name>site 4</name>             <url>http://www.site.com</url>         </link>         <link>             <name>site 5</name>             <url>http://www.site.com</url>         </link>     </links> </div> </dynamic_div> 

so have jquery. ideas on how simplified need do?

$(function(){   $.ajax({     type: "get",     url: "dev_test.xml",     datatype: "xml",     success: function(xml) {         $(xml).find('content').each(function() {             var set = $(this).attr('set');              if(set == 1)             {                 var words = $(this).find('p').text();                 $('<p>').html(words).appendto('#set_1');              }             if(set == 2)             {                 var name    = $(this).find('name').text();                 var img     = $(this).find('source').text();                 var alt     = $(this).find('alt').text();                 $('<img />').attr('src',img).attr('alt',alt).attr('title',name).appendto('#set_2');                 //('<img />').data(words).appendto('#set_2');              }             if(set == 3)             {                 var words = $(this).find('p').text();                 $('<p>').html(words).appendto('#set_3');              }         });     } });  }); 

i know looking more switch case begin with:

switch(set)         {          case 1:             var words = $(this).find('p').text();             $('<p>').html(words).appendto('#set_1');             break;         case 2:             var name    = $(this).find('name').text();             var img     = $(this).find('source').text();             var alt     = $(this).find('alt').text();             $('<img />').attr('src',img).attr('alt',alt).attr('title',name).appendto('#set_2');             //('<img />').data(words).appendto('#set_2');            break;         case 3:             var words = $(this).find('p').text();             $('<p>').html(words).appendto('#set_3');             break;         } 

and jquery parsexml may rest: http://api.jquery.com/jquery.parsexml/


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -