3

I'm trying to use jQuery to change an image every 15 seconds so this works in all browsers. I have tried removing this markup and leaving the div empty and using jQuery to change the background-image url>

How can the image url be changed with jQuery

Given this markup;

<div id="logotransitions" runat="server">
    <asp:Image ID="Image1" runat="server" ImageAlign="AbsMiddle"
                           ImageUrl="~/Images/MainLogo_png_270x180.png" />
</div><!--logotransitions  -->

2 Answers 2

6

You can get the client side ID of the Image tag and change the source of the Image like below

$("#<%=Image1.ClientID%>").attr('src','http://image/url.jpg');

It will change the src attribute of the img tag

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

1 Comment

Year right.. you must add this code in the same file where your code resides. and also jquery should load before the function call
1

<asp:Image> should be rendered as an tag. Hence you should be able to modify the src property.

$('#logotransitions > img').prop({ src: 'someimage.png' });

4 Comments

if i have three images in that div how can i put their url src's in an array becuase this doesn't work var arrayOfImages = $('#logotransitions').find('img').map(function () { return this.attr('src'); }).get();
@dinotom Try changing this.attr('src'); to $(this).attr('src');. You are trying to run a jQuery method on a dom element.
i tried to upvote you for this but trigger finger double clicked which resulted in upvote and recall of it and it wont let me do it again
@dinotom Are you referring to my last comment? Did it help you out? As long as it's working for you I'm happy ;-)

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.