-1

I am getting this object value as string

'{gallery: 'gal', smallimage: 'http://www.website.com/image.jpg',largeimage: 'http://www.website.com/image1.jpg'}'

How can i read this using jquery? Currently i am using this following function as bellow to read this but i can't find value in $each

$(".jcarousel-item a").click(function() {
    alert($(this).attr("rel"));//I can find this object value here
    $.each($(this).attr("rel"), function(index, value) { 
        alert(index + ': ' + value); 
    });
});
Sandeep Tawaniya
  • 717
  • 8
  • 17

2 Answers2

-1

You do not have to depend on jQuery for this:

var i;
var array =$(this).attr("rel");
for (i = 0; i < array.length; ++i) {
   // do something with `array[i]`
}
renakre
  • 8,001
  • 5
  • 46
  • 99
-1

Try to parse the array as this:

$(".jcarousel-item a").click(function() {
    var arrayData = $(this).attr("rel");
    var objData = JSON.parse(arrayData);
    // Here objData is a JSON, you can access how this
    alert(objData.gallery);
    alert(objData.smallimage);
    alert(objData.largeimage);
});
oscarvady
  • 450
  • 1
  • 4
  • 12