Questions tagged [src]

SRC is a common attribute in HTML used to identify the location of a resource which relates to an element.

Within HTML, several elements may make use of the src attribute in order to identify a resource to which the element may relate. It is normally a "valid non-empty URL potentially surrounded by spaces".

Questions often arise relating to the attribute due to confusion between absolute and relative URLs, how src URLs relate to the location of files, and browser caching.

Some examples of elements which use the src attribute are:

  • IMG

    Specifies a URL referencing a non-interactive, optionally animated, image that is neither paged nor scripted.

  • IFRAME

    Gives the address of a page that the nested browsing context is to contain.

  • SCRIPT

    Gives the address of the external script resource to use.

  • EMBED

    Gives the address of the resource being embedded.

  • VIDEO

    The URL for the video.

  • AUDIO

    The URL for the audio stream.

  • TRACK

    Gives the address of the timed track data. This attribute must be present.

There are other elements which may make use of the src attribute, which may be discovered at the W3C Community Wiki.

Related tags: , , , ,

1799 questions
46
votes
4 answers

Add transition while changing img src with javascript

I have an img tag that I want to change the src when hover and it all works but i would like to add some transition so it doesn't look so rough but since it's an img src i cant target it with css. http://jsfiddle.net/Ne5zw/1/ html
ernerock
  • 542
  • 1
  • 4
  • 6
44
votes
4 answers

How to set the image src using jQuery

I am trying to change the image src attribute using jQuery jQuery("#imageID").attr('src','http://localhost:8080/images/1/myImage.png' ); using the above code i can change the src attribute, but when i try this:-…
Rakesh Juyal
  • 35,919
  • 68
  • 173
  • 214
38
votes
5 answers

src absolute path problem

I have an image in C:\wamp\www\site\img and i try to display it in a page with this: but it's not working.The file is actually there and if I try to refer to it with a relative path i got the…
luca
  • 36,606
  • 27
  • 86
  • 125
37
votes
6 answers

What is my script src URL?

Is there a simple and reliable way to determine the URL of the currently-executing JavaScript file (inside a web page)? My only thought on this is to scan the DOM for all the script src attributes to find how the current file was referenced and then…
Neil C. Obremski
  • 18,696
  • 24
  • 83
  • 112
34
votes
3 answers

What is the right way to write my script 'src' url for a local development environment?

I'm working on a local environment and I'm not sure if I've written my src URl correctly because my functions aren't working. The bold script tag has the src in question.
Spilot
  • 1,495
  • 8
  • 29
  • 55
33
votes
12 answers

Change image source with JavaScript

So I'm new with JavaScript (this is actually my first attempt to make something work) and I'm having a bit of trouble. I thought I had enough knowledge to make this work, I've even googled for tutorials and scripts that could help me work this out…
Alvaro Arregui
  • 579
  • 1
  • 5
  • 9
33
votes
2 answers

find image src that :contains?

Morning all, I have a list of images like so: Using jQuery how find all image src's within…
Charles Web Dev
  • 429
  • 2
  • 7
  • 12
30
votes
5 answers

see if src of img exists

when I place an img tag I create the src attribute dynamically. Is there a way of testing if the src (path where the image is located) actually exists with javascript in order to avoid getting:
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
29
votes
8 answers

Regular Expression to get the SRC of images in C#

I'm looking for a regular expression to isolate the src value of an img. (I know that this is not the best way to do this but this is what I have to do in this case) I have a string which contains simple html code, some text and an image. I need to…
zekia
  • 4,527
  • 6
  • 38
  • 47
29
votes
4 answers

Setting an image src to empty

I would like to set an image as nothing. By doing src="" many people say it can cause problems to browsers: http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/ so I am not sure if below can face to the same problem as…
user304602
  • 991
  • 4
  • 21
  • 39
25
votes
10 answers

iframe without an src attribute

I would like to create an