I'm trying to define an area in a jQuery snippet that is easy for a user to alter. The end goal is the user defines the values, but the jQuery will create the objects from the list.
I start with this simple HTML div:
<div class="slider-container"></div>
Followed by the js concept:
var newSlides = [];
$(".slider-container").each(function(){
newSlides.push({
image: {
url: "http://placekitten.com/960/400",
title: "Sample Title 1",
subtitle: "Sample Subtitle 1"
},
image: {
url: "http://placekitten.com/961/401",
title: "Sample title 2"
};
});
});
I would like it to be able to then take these values and do something like:
var index = 1;
$("slider-container").append(
$("<div/>", {class: "slide s-" + index++})
.append($("<img/>, {src: "url-from-above"}))
.append($("<div/>, {class: "slide-titles"})
.append($("<h2/>, {class: "title").text("text-from-above))
.append($("<h3/>, {class: "subtitle").text("text-from-above))))
So that the final result would be:
<div class="slider-container">
<div class="slide s-1">
<img src="http://placekitten.com/960/400 />
<div class="slide-titles">
<h2>Sample Title 1</h2>
<h3>Sample Subtitle 1</h3>
</div>
</div>
<div class="slide s-2">
<img src="http://placekitten.com/961/401" />
<div class="slide-titles">
<h2>Sample Title 2</h2>
</div>
</div>
</div>
The goal being a user just has to define values and not have to worry about defining the HTML or putting things in the correct places. Easy to edit for anyone.