src attribute | src property

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
0 out of 1 rated this helpful - Rate this topic

Sets or retrieves a URL to be loaded by the object.

Syntax

HTML<element src="p" ... >
JavaScript

p = object.src

Property values

Type: String

The URL.

Remarks

The value of the src attribute of the img and input type=image elements depends on the context of the reference to the attribute. When read as a Document Object Model (DOM) attribute, src returns a URL relative to the hosting domain. The value specified by the page author is returned when src is read as a content attribute, when the page is displayed in an earlier document compatibility mode.

Windows Internet Explorer 8 or later. In IE8 Standards mode, the value of the src attribute of the img and input type=image elements depends on the context of the reference to the attribute. When read as a DOM attribute, src returns a URL relative to the domain hosting the Web page. The value specified by the page author is returned when src is read as a content attribute, when the page is displayed in an earlier document compatibility mode, or when the page is viewed with an earlier version of the browser. For more information, see Attribute Differences in Internet Explorer 8.

Examples

This example uses the src property to change the image's src attribute.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/src.htm


<body onmousedown="oImage.src='sphere.png'" onmouseup="oImage.src='cone.png'">
... 
	<img id="oImage" src="cone.jpeg">

</body>

See also

img
input type=image
HTMLInputElement

 

 

Send comments about this topic to Microsoft

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

© 2013 Microsoft. All rights reserved.