jquery - replaceWith doesn't work the second time -


i need click on list item replace text in div text node in xml file.

i click on list item , store result in variable. load xml, find title of node need, , make variable of result. run if statement if 2 variables equal, put xml in div.

the first time click on list item, works. correct item in list matched correct node in xml , correct text placed in div.

but when click on different list item, text not replaced. alert shows second click got right information, in end, div content not replaced.

demo here: http://mwebphoto.com/mwebphoto/html/3rdjquerypage.html

code here:

<body>  <div class="slideshowcontainer"> <div id="slideshow"></div> </div>  <ul id="gallery_id">   <li id="newyork">new york</li>   <li id="disconnection">disconnexion</li>   <li id="jackatsea">jack @ sea</li> </ul>  <script>    $(document).ready(function(){     $("#gallery_id li").on('click', function(e) {       var htmltitle = (this.id);  $.ajax({   type: "get",     url: "/mwebphoto/xml/albums.xml",     datatype: "xml",     success: function(xml) {         $(xml).find('photoalbum').each(function(){             var xmlalbum= $(this);             var xmltitle = $(this).find('title').text();             var xmlembedcode = $(this).find('embedcode').text();                 alert ('this html titled  ' + htmltitle);                 alert ('this xml titled  ' + xmltitle);             if(xmltitle=htmltitle)               alert ('this matched xml title' + xmltitle);           $("#slideshow").replacewith(xmltitle);          });     } }); });  });    </script> </body> 

help appreciated. don't ask lightly. i've spent many hours @ , researched every way can think of. figure i'm missing simple, can't find it.

after executing first time, $("#slideshow") doesn't exists anymore, you're replacing whole div id xml.

what need text():

$("#slideshow").text(xmltitle); 

or html() if plan add html:

$("#slideshow").html(xmltitle); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -