I try to append elements form xml data file.I success to do it onload. I append on load a certain number of element.I want to use this append function to add next elements form the same xml data on click.To do this, I add a condition if and variables. However nothing happen..I think I have a problem with my if.Here my script EDIT WORKING SCRIPT:\[code\]$(document).ready(function() {var $container = $('#container');var $items = $('.element');var $filter = $('#filter a');function initIsotope() { $container.isotope({ itemSelector: $items, animationOptions: { duration: 4000, easing: 'easeInOutQuad', queue: false } }); $filter.on('click', function(){ $container.isotope({ filter: this.getAttribute('data-option-value') }) }); $(' #container > div ').each( function() { $(this).hoverdir(); } );}$.get('data.xml', function (d){ first = $(d).find("element").last().attr("id"); last = $(d).find("element").first().attr("id"); init(); });$('#next').on("click", function() { init(); $('#container').isotope({itemSelector: '.element', });});function init(){$.get('data.xml', function (d){ var nbOfelemet = 1; var nbToappend = last - nbOfelemet; alert(last); alert(nbToappend); $(d).find('element').each(function (){ if ( $(this).attr("id") <= last ) { var $element = $(this); var id = $element.attr("id"); var size = $element.attr("size"); var category = $element.attr("category"); var urlpage = $element.find('urlpage').text(); var urlimage = $element.find('urlimage').text(); var title = $element.find('title').text(); var $newelement = $('<div class="element '+ size +' '+category +'" id="_'+id+'"></div>').html('<a class= "link" href="' + urlpage + '"><img src="' + urlimage + '" class="thumbnail" />' + '<div>' + '<span>' + '<i class="icon-pencil"></i>' + ' ' + title + '</span><span class="more">more.</span></div></a></div>');$container.isotope( 'insert', $newelement)var next = id; last = id -1 ; if ( first == next ) { $("#next-container").fadeOut(500);} return ( id != nbToappend); } }); initIsotope(); });}})\[/code\]