javascript - jQuery change html on clone -


on click copying div. wish alter of html , append.

i have tried following, clone , append cant seem alter html. not sure best way handle it, sure have wrong.

thanks

var htmlstr = $(this).parents(".listingcontainer").first(); $htmlstr.find(".savecompareshow").remove() $(htmlstr).clone().appendto('.comparewrapper');                          

once have cloned dom element should treat though wanted change dom element isn't being cloned. use variable instead of selector.

assuming have html this:

​<div class='listingcontainer'>     <div class='listing'>             </div>     <div class='listing'>             </div> </div> 

you can clone contents of listingcontainer div , change contents before appending them comparewrapper div. following javascript shows simple example:

$(document).ready(function() {     $('.listing').click(function() {         var $htmlstr = $(this).parents(".listingcontainer").first();         $htmlstr.clone().find('.listing').html('<li>cloned</li>').appendto('.comparewrapper');     }); }); 

i've posted jsfiddle can see working: http://jsfiddle.net/hkbmk/


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -