2

I want to add a DOM dynamic ID into an image url. The current img src url has values, but I want to insert values through variables DOM objects.

Movie.Imdb is a variable that I want the img src to dynamically render.

<div id=imdb style="visibility: hidden;">{{movie.id}}</div>
              
<div  src="http://img.omdbapi.com/?i=tt3896198&h=600" ></div>

I want the image src url to be rendered as:

http://img.omdbapi.com/?i=+"imdb"+&h=600    

So that it can be dynamic.

ouflak
  • 2,458
  • 10
  • 44
  • 49
  • what do you want exactly..? – Bhuwan Jan 22 '18 at 12:22
  • i want to create a url like this : img src="http://img.omdbapi.com/?i=+"imdb" " instead of http://img.omdbapi.com/?i=88888..... i should be dynamic.... i want to pick up value using document.getElementById which i will define in the script to take dynamic values.... –  Jan 22 '18 at 12:25
  • img src url i want to use in my html –  Jan 22 '18 at 12:26
  • you want to create a `` element as well...? – Bhuwan Jan 22 '18 at 12:39
  • this is called templating. Use any templating engine to do such adventures... – Ashish Kumar Jan 24 '18 at 05:53

2 Answers2

0

Try to use of append() and attr() jQuery

Stack Snippet

var imageUrl = $("#imageUrl").attr("src");
$(".wrapper").append("<img src=" + imageUrl + ">")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
  <div id="imageUrl" src="http://img.omdbapi.com/?i=tt3896198&h=600&apikey=6c3a2d45"></div>
</div>
Bhuwan
  • 16,525
  • 5
  • 34
  • 57
0
<div  src="http://img.omdbapi.com/?i="+movie.id+"&h=600" ></div>

This should work.

ouflak
  • 2,458
  • 10
  • 44
  • 49
shawn bwz
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 10 '21 at 07:22