2

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.

2
  • 1
    what exactly do you need here? Commented Oct 14, 2013 at 7:59
  • I want to extract the url of the current image using javascript. Commented Oct 14, 2013 at 8:06

2 Answers 2

5

in 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.

Sign up to request clarification or add additional context in comments.

8 Comments

The message returned when i do this is "undefined".
I need to getElementbyID of the show_banner, then get the image url
try with jQuery: $('#elementId img').attr('src')
you may be using duplicated IDs ?
You should only have one element assigned with a unique id (using the id attribute); do not give multiple elements the same id. Try using the class attribute or even the name attribute itself.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.