3

How can I append an Image using a jquery function with 1 param?

function imageadd(param1){
    $('#random').append(...)
}

with the src being src="gallery/param1.jpg"

2 Answers 2

3
function imageadd(param1)
{
    $('#random').append("<img src='gallery/" + param1 + ".jpg'");
}
Sign up to request clarification or add additional context in comments.

Comments

2

Create a new img element and assign the src attribute. Aassuming param1 was the src you could do it like this:

function imageadd(param1){
    $('#random').append($('<img />').attr('src','gallery/' + param1 + '.jpg'));
}

or, if param1 is the full url already:

function imageadd(param1){
    $('#random').append($('<img />').attr('src', param1));
}

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.