-1

I have a jquery script that sets a few options on page load.

However I want to set the image in a sitemap with id #User_Menu_Options_TreeView1t8

How do i achieve this ? ( as I have searched this site and not found exactly what am looking for )

many thanks

E

  • 1
    See this: http://stackoverflow.com/questions/540349/change-the-image-source-using-jquery – Hakim Jul 24 '13 at 23:36

2 Answers2

0

Set the image in a sitemap? If you want to change the background image of an item based on the ID, you could do something like this:

$(document).ready(function() {
     $("#User_Menu_Options_TreeView1t8").css("background", "url:('myimagelocation.png')");
});

If I misunderstood, and you already have an image on the page but you want to change the source, you could do this:

$(document).ready(function() {
     $("#User_Menu_Options_TreeView1t8").attr("src", "myimagelocation.png");
});

Hope this helps.

0

Get the image and set its src with the data

$(function () {
    var myUrl = "/Content/Images/" + $('#MyId').val();
    $('#myImage').attr('src', myUrl);
});
dan_vitch
  • 4,477
  • 12
  • 46
  • 69