2

I have two inline HTML images.

For sake of brevity, let's just say this particular mark-up is really difficult to get to, where these two images live.

One image has an ID, the other image does not, but it has a parent div with an ID. What I would like to do is, update / change the src="" of each, with raw JS or preferably smaller jQuery.

Image #1

<img id="log_im" src="./wp-content/uploads/2015/01/old_logo.png">

Image #2

<div id="txt_left">
<img style="max-width: 300px; margin-left: -14px;" src="./wp-content/uploads/2015/01/outdatedimage.png">
</div>

4 Answers 4

5
$("#log_im").attr('src', 'http://www.example.com/image.jpg');

$("#txt_left img").attr('src', 'http://www.example.com/image.jpg');
Sign up to request clarification or add additional context in comments.

Comments

1

First image:

$('#log_im').attr('src','newRoute.png');

Second image

$('#txt_left img').attr('src','newRoute.png');

Comments

0

Really no need to use jQuery for this:

var img_log_im = document.getElementById("log_im");

img.log_im.src = "image url";

var div_txt_left = document.getElementById("txt_left");
div_txt_left.children[0].src = "image url";

Alternatively:

var img_log_im = document.querySelector('#log_im');

var div_txt_left_img = document.querySelector("#txt_left img");

Comments

0

In jQuery do both together -

$('#log_im, #txt_left img').attr('src','newRoute.png');

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.