How to show an image using javascript?

Asked

Viewed 1,205 times

0

The following code is in javascript:

<img class=\"modal-loading\" src=\"~/Content/img/loading.gif\" />

The final result:

inserir a descrição da imagem aqui

  • What do you mean by "in my javascript"? Why the tag img would be in your js file and not in HTML? Have you tried using the absolute image path?

  • This code above, not in html, is in javascript. Because I am using a plugin and I want to change style... I can only change using js Example: templates:{ header: "div class="" .......<img clas =....etc ../.> <button class="btn btn-success"}

  • 1

    And the absolute way, tried?

  • By the absolute way it works, it has how to make it work by the relative way ?

  • 1

    Try using the root path of the application, so not the user directory.

1 answer

1


good night Have you tried to get ~ from the address ? everything will depend on the directory that is img if it is in a subdirectory of your web project just put Content/img/loading.gif

  • It worked, just remove til character. src=\"/Content/img/loading.gif\"

  • 1

    Exactly. Removing the character ~, the path is relative to the root directory of the application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.