I'm having problems with the following piece. I'm trying to create some gallery of my own, but I'm in the very early beginning of learning jQuery, and all this array stuff is pretty hard for me to understand..
In my CMS I have created a looped output in the following form for all elements:
<img class="content" src="path/to/image1.jpg" />
<p class="title">Description1</p>
<a class="link_img" href="http://www.somesite1.com" target="_blank">Link to Site1</a>
<img class="content" src="path/to/image2.jpg" />
<p class="title">Description2</p>
<a class="link_img" href="http://www.somesite2.com" target="_blank">Link to Site2</a>
But I need to bring it into this form (for my jQuery playground):
var myDemoImages = [
{ src: 'path/to/image1.jpg', title: 'Description1', subtitle: 'http://www.somesite1.com' },
{ src: 'path/to/image2.jpg', title: 'Description2', subtitle: 'http://www.somesite2.com' }
];
I tried something like the following, but it's mixing up values, doubling values.
$('img.content').each(function() {
for (var k = 0; k < this.attributes.length; k++)
{
var attr = this.attributes[k];
if (attr.name != 'class')
myImages.push("src:'"+attr.value+"'");
}
});
Also the "value" I need from the p tag is actually not a value, but shouldn't something like this work?
myImages.push(this.innerHTML);