0

The path to an image looks like this:

<img src="uploads/image1.jpg">

The image is visible when on index.php in the same directory as uploads is. But for my admin, i use a subdirectory admin. So to view the image, the path now should be

<img src="../uploads/image1.jpg">

Is it possible to add the ../ before the uploads with jquery? and how can i do that?

I want to make this work for all images in the uploads folder!

john
  • 1,263
  • 5
  • 18

2 Answers2

1

This jQuery function will change all images src:

$.each($("img"), function(){$(this).attr("src","../"+$(this).attr("src"));});
console.log($("body").html());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="uploads/image1.jpg">
<img src="image1.jpg">
<img src="uploads/image9.jpg">
Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30
0

you can do like this...

$('#image').click(function() {
  $('#picture').attr('src': '../uploads/image1.jpg')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="image">
  <img src="uploads/image1.jpg" id="picture" />
</div>

see this answer change img src on click

prasanth
  • 22,145
  • 4
  • 29
  • 53
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43