You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > script

script object

Browser support:
Specifies a script block within a HTML document.
The script element allows authors to write or include script codes into HTML documents.
Use the type property to specify the language for a script block. If the type property is not specified (it was only required in older browsers), JavaScript (JScript) is the basic interpreter for the code.
The script tag should be placed in the head or in the body element.

Syntax:

Methods that return the object:
document.createElement ("script")
scripts.item (nameOrIndex [, subIndex])
scripts.namedItem (name)
The base interface, through which you can add new functionalities to the script object, is the HTMLScriptElement interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: script

Possible members:

Properties
Methods
Events
Style properties
attributes
Represents a collection of attribute nodes that belong to an element.
baseURI
10
Returns the base URL for the object.
behaviorUrns
Represents a collection of the Uniform Resource Names for all behaviors attached to an element.
canHaveChildren
Retrieves a Boolean value that indicates whether the element can contain child elements.
canHaveHTML
Retrieves a Boolean value that indicates whether the element can contain HTML formatted text.
charset
Sets or retrieves the character encoding of the document, a linked document or a script block.
currentStyle
Represents the computed style settings for an element.
defer
3.5
Sets or retrieves whether the script is going to generate any document content.
event
Sets or retrieves an event that the script element should listen for.
htmlFor
Sets or retrieves the identifier of the element to which the script is bound when a specific event is fired for the element.
id
Sets or retrieves a unique identifier for the object.
isContentEditable
Returns a Boolean value that indicates whether the contents of the object are editable by the user.
isDisabled
Returns a Boolean value that indicates whether the object is disabled.
isMultiLine
Returns a Boolean value that indicates whether the contents of an element can be multiline or not.
isTextEdit
Returns a Boolean value that indicates whether the createTextRange method can be used for the element.
lang
Specifies or returns the language of the element.
language
Sets or retrieves the scripting language for the current element. Use it only for the script element.
localName
9
Returns the local part of the qualified name of the current node.
name
Sets or retrieves the name of an element.
namespaceURI
93.6
Sets or returns the namespace URI of the current node.
nextElementSibling
93.5
Returns a reference to the next child element of the current element's parent.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeValue
Sets or returns the value of the current node.
outerHTML
Sets or retrieves the outer HTML content (the source code including the opening and closing tags) of an element.
outerText
Sets or returns the text content of an element including the text content of its descendants.
ownerDocument
Returns the document object that contains the current node.
parentElement
Returns the parent element of the object in the DOM hierarchy.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
parentTextEdit
Returns the closest ancestor element of the current element in the DOM hierarchy that can be used to create a TextRange object.
previousElementSibling
93.5
Returns a reference to the previous child element of the current element's parent.
previousSibling
Returns a reference to the previous node of the current element's parent.
readyState
Returns a string value that represents the state of the object.
runtimeStyle
Represents the overridden style settings for an element.
scopeName
Retrieves the local name of the namespace declared for the current element.
sourceIndex
Returns the position of the current object in the all collection of the document.
src
Sets or retrieves the location of a file containing scripting code.
style
Represents the inline style settings for an element or a CSS rule.
tagName
Returns the tag name of the current element.
tagUrn
Sets or retrieves the Uniform Resource Name (URN) of the namespace declared for the current element.
text
Sets or returns a string that corresponds the contents of the element.
type
Sets or retrieves the type of scripting language to use.
uniqueID
Returns the unique identifier generated by the browser for the object.

Example HTML code 1:

This example illustrates the use of the script element:
<head>
    <script type="text/javascript">
        window.onload = alert ("Fires onload event.");
    </script>
</head>
Did you find this example helpful? yes no

Example HTML code 2:

This example shows how to link a .js (JavaScript) file into a HTML document:
<head>
    <script type="text/javascript" src="sample.js"></script>
</head>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content