I have a Jquery function that have many url for image ojbect. How can i get the url of the image using javascript. I want to make a test on the url
if url=condition {//do something...
You can find below example of the code.
$(document).ready(function () {
$(function () {
$("#show_banners").showcase({
css: {
"margin-left": "auto",
"margin-right": "auto"
},
animation: {
type: "fade",
interval: 4500,
speed: 1800
},
images: [{
url: "../images/content/example1.jpg",
description: "example1",
target: "_self",
link: ""
}, {
url: "../images/content/example2.jpg",
description: "example2",
target: "_self",
link: ""
}, {
url: "../images/content/example3.jpg...
The ID of the DIV is show_banners
.
I have a Jquery function that have many url for image ojbect. How can i get the url of the image using javascript. I want to make a test on the url
if url=condition {//do something...
You can find below example of the code.
$(document).ready(function () {
$(function () {
$("#show_banners").showcase({
css: {
"margin-left": "auto",
"margin-right": "auto"
},
animation: {
type: "fade",
interval: 4500,
speed: 1800
},
images: [{
url: "../images/content/example1.jpg",
description: "example1",
target: "_self",
link: ""
}, {
url: "../images/content/example2.jpg",
description: "example2",
target: "_self",
link: ""
}, {
url: "../images/content/example3.jpg...
The ID of the DIV is show_banners
.
- 1 what exactly do you need here? – geevee Commented Oct 14, 2013 at 7:59
- I want to extract the url of the current image using javascript. – user2878048 Commented Oct 14, 2013 at 8:06
2 Answers
Reset to default 5in order to extract a src from an image in JavaScript:
var img_src = document.getElementById('elementId').src;
in jQuery:
var img_src = $('#elementId').attr('src');
hope that helps.
Like so:
var image_array = []
for(var i=1; i<=5; i++) {
image_array.push({
url: "../images/content/example"+i+".jpg",
description: "example"+i,
target: "_self",
link: ""
})
}
Change i<=5
to the amount of rows you have. Then in the code you posted above put:
images: image_array