Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to replace src content in image control in jquery?

Posted on 2014-09-24
3
Medium Priority
?
166 Views
Last Modified: 2014-09-27
Hi,
I have this jquery code below that works fine with the label web control. What it basically does is to find the webcontrol with the specific id and eval the data from xml table.

Works fine
=================
$(".filename", table).html(customer.find("filename").text());

<asp:Label ID="lblFilename" class="filename" runat="server" Text='<%# Eval("filename")%>'></asp:Label>



Now what if i want to use the same application on a image control? The below doesn't work

Not working
==============
$(".imgPhoto", table).html(customer.find("filename").text());

<img class="imgPhoto" src='<%# Eval("filename")%>' />

Any help is greatly appreciated.
0
Comment
Question by:tangteng78
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 1000 total points
ID: 40342044
If you want to change the img src

$(".imgPhoto", table).attr("src","newsource.jpg")
0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 1000 total points
ID: 40342124
try this :

jQuery(function($) { // be sure to wait complete page loading of the page, similar to window.onload or $(document).ready(function() {
     var filename = $("<%= lblFilename.ClientID %>").text();
     $("table .imgPhoto").attr("src", filename);
});

Open in new window

0
 

Author Closing Comment

by:tangteng78
ID: 40347469
Bulls eye
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question