You are here: Reference > JavaScript > client-side > HTML DOM > properties > src (embed, iframe, img, xml, ...)

src property (embed, iframe, img, xml, ...)

Browser support:
Sets or retrieves the location of an associated file for an object.

Syntax:

object.src;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: src

Possible values:

String that sets or retrieves the URL of the associated file. It can be an absolute or relative path as well. Relative paths are relative to the base URL. The base URL is the location of the current document, but it can be overridden by the base tag.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the src attribute:
<img src="area.gif" width="504px" height="126px" />
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the src property:
<head>
    <script type="text/javascript">
        function GetSrc () {
            var image = document.getElementById ("myImage");
            alert (image.src);
        }
    </script>
</head>
<body>
    <img id="myImage" src="area.gif" width="504px" height="126px" />

    <button onclick="GetSrc ();">Get image location!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content