0

I used jquery isotope to display my portfolio. I want to load all isotope item thanks to an xml file.

I tried to append isotope element with jquery and xml data.

My script looks like to this :

$(document).ready(function()
  {
$.get('data.xml', function (d) {

    $(d).find('element').each(function () {
        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();

$('<div class= " element '+ size +' '+ category +' " id="_'+id+'"></div>').html('<a class= "link" href="' + urlpage + '"><img  src="' + urlimage + '" class="thumbnail" />' + '<div>' + '<span>' + + '<span>' + '<i class="icon-pencil"></i>' + '&nbsp;&nbsp;' + title + '</span><span class="more">more.</span></div></a></div>').appendTo('#container');


});

$container.isotope({
    itemSelector : '.element',
    layoutMode: 'masonryHorizontal',
    masonryHorizontal: {
    rowHeight: 210
    },
});

});
});

And my xml like this:

<?xml version="1.0" encoding="utf-8" ?>

<element>
    <element id="13" size="" category="portfolio">
    <urlpage>/portfolio/dock.html</urlpage>
    <urlimage>./Post thumbnail images/formlabs.jpg</urlimage>
    <title>Formlabs : An offordable 3D printer on kickstarter</title>
</element>

<element>
    <element id="12" size="" category="portfolio">
    <urlpage>/portfolio/dock.html</urlpage>
    <urlimage>./Post thumbnail images/Bumper.JPG</urlimage>
    <title>Minimal Bumper for iPhone 5</title>
</element>

But nothing happens....I think I have a mistake in my script....

What's wrong?

Sorry for my Englis, I'm French.

1 Answer 1

1

Your XML is invalid. You have an element and inside it you have another one which is not closed. Additionally all your tags must be inside a root tag (for example elements).

Why don't you do it like this:

<?xml version="1.0" encoding="utf-8" ?>
<elements>
<element id="13" size="" category="portfolio">
    <urlpage>/portfolio/dock.html</urlpage>
    <urlimage>./Post thumbnail images/formlabs.jpg</urlimage>
    <title>Formlabs : An offordable 3D printer on kickstarter</title>
</element>

<element id="12" size="" category="portfolio">
    <urlpage>/portfolio/dock.html</urlpage>
    <urlimage>./Post thumbnail images/Bumper.JPG</urlimage>
    <title>Minimal Bumper for iPhone 5</title>
</element>
</elements>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I saw this jsut 2min ago... Now my appended elements works. However, if I append inside my isotope container (#container) nothing happens... If I append in another non isotope container it works.
I success to append elements to container. But Isotope call back is not working...
Ok i Find with this : $container.isotope( 'insert', $('<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>' + '&nbsp;&nbsp;' + title + '</span><span class="more">more.</span></div></a></div>'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.