Carousel Image Slider using XML Data with jQuery jCarousel Plugin

← PrevNext →

We are in the age of visual culture and having said that images play a very important role in displaying your work, product etc to your audience. You need images for your online store, publish photographs on your blog and more. Image sliders, are best known for displaying multiple images in a single container. Here, in this post I’ll show you how to create a simple Carousel image slider using jQuery jCarousel Plugin. I'll extract image details, such as, name etc. from an XML file.

The jCarousel Plugin provides features to create a Carousel like image slider using HTML contents. In the example here, I’ll extract a list of images properties from an XML file dynamically using jQuery Ajax. Once the details of the images are extracted, I’ll add the images to HTML <li> tag. Finally, add the <li> with the <img> to a pre-declared <ul> tag using jQuery appendTo method.

See this demo

Browser Support:
Chrome 39.0 - Yes | FireFox 34.0 - Yes | Internet Explorer 10 - Yes | Safari 5.1.4 - Yes

Once we have all the images, and created the markup for the web page, we will ask the Plugin to create the image slider.

First, we will create an XML document and add the source of each image and some miscellaneous properties to it.

<?xml version="1.0"?>
<!--   Last edited by https://www.encodedna.com   -->
    <alt>All Plugins</alt>
    <alt>Beginners Guide</alt>
    <alt>XML for Beginners</alt>
    <alt>HTML5 Tips</alt>

The child nodes <image> have URL for each image in the root folder. However, you may add a folder name, if the images are inside another folder. For example


The Code
<!doctype html>
    <title>jQuery jCarousel Plugin Example</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/jcarousel/0.2.9/jquery.jcarousel.min.js"></script>
    <link rel="Stylesheet" href="https://cdn.jsdelivr.net/jcarousel/0.2.9/skins/tango/skin.css" />

    <p>jQuery jCarousel Plugin Example! Click the arrows to scroll images.</p>
    <ul id="show_images" class="jcarousel-skin-tango">

    $(document).ready(function () {

            type: 'GET',
            url: 'https://www.encodedna.com/library/images-source.xml',
            dataType: 'xml',
            success: function (xml) {
                $(xml).find('ref').each(function () {

                    var li = $('<li/>');

                    img = $(this).find('image').text();
                    alt = $(this).find('alt').text();

                    $('<img />')
                        .attr('src', "" + img + "")         // ADD IMAGE PROPERTIES.
                        .attr('alt', alt)

                        .appendTo(li)                       // ADD EACH IMAGE TO LI.

                    // ADD LI (WITH THE IMAGE) TO THE UL.

Try it

Browser Support:
Chrome 39.0 - Yes | FireFox 34.0 - Yes | Internet Explorer 10 - Yes | Safari 5.1.4 - Yes

See this demo

Thanks for reading 🙂.

← PreviousNext →