Method instance of HtmlElement object

Source: Internet
Author: User
Tags manual html tags

Method instance of HtmlElement object

The HtmlElement object inherits the standard methods of node and element objects. Some types of elements implement markup-specific methods, and W3school provides information about these methods in each markup reference page of the HTML DOM Reference manual.

Most modern browsers also implement non-standard methods such as the following:

Method description
scrollIntoView () scrolls the document. Causes the element to appear at the top or bottom of the window.
Event handle for HtmlElement object
All HTML elements that respond to mouse and keyboard events can trigger the event handles listed here. Some elements, such as links and buttons, perform the default actions when these events occur. For elements like this, more details can be found in the reference page of the concrete element.

See the HTML Event Properties Reference manual for more information about HTML event handles.
How to get more detailed information about the HtmlElement object
In the W3school HTML DOM Reference Manual, we make a special reference page for the DOM object corresponding to the HTML tag:

var obj = {Nodetype:1};
function Ishtmlelement (obj) {
if (Obj.nodetype) {
return obj.nodetype==1;
}
}


Ishtmlelement (obj);//true
Ishtmlelement (obj) returns true, but obj is obviously not an HTML node element

function Ishtmlelement (obj) {
var d = document.createelement ("div");
try{
D.appendchild (Obj.clonenode (true));
return obj.nodetype==1?true:false;
}catch (e) {
return false;
}
}
var obj1 = {Nodetype:1};
var obj2 = document.createTextNode ("Hello");
var obj2 = document.createelement ("P");
Ishtmlelement (obj1);//false
Ishtmlelement (OBJ2);//false
Ishtmlelement (OBJ3);//true


window and document have to be handled in particular.

function Ishtmlcontrol (obj) {

var d = document.createelement ("div");
try{
D.appendchild (Obj.clonenode (true));
Return obj.nodetype==1? True:false;
}catch (e) {
return Obj==window | | Obj==document;
}
}


Nodetype==1 determines whether an element is a hmtlelement element. The elements on the page are nodes, element nodes, attribute nodes, text nodes, and so on, and so on. The NodeType of the Consortium

Const unsigned short element_node = 1;
Const unsigned short attribute_node = 2;
Const unsigned short text_node = 3;
Const unsigned short cdata_section_node = 4;
Const unsigned short entity_reference_node = 5;
Const unsigned Short entity_node = 6;
Const unsigned Short processing_instruction_node = 7;
Const unsigned short comment_node = 8;
Const unsigned Short document_node = 9;
Const unsigned short document_type_node = 10;
Const unsigned short document_fragment_node = 11;
Const unsigned short notation_node = 12;


Each element in an HTML document has an attribute corresponding to the HTML attribute of the element. This lists the properties that are supported by all HTML tags. The other attributes are specific to a specific HTML tag. The HtmlElement object inherits the standard attributes of node and element objects, and also implements several non-standard properties described below:


ClassName
Specify the class attribute of the element. Note: This property name is not "class" because "class" is a reserved word in a Web page effect.

Type: String. Status: Writable.

Currentstyle
This property that is specific to IE is applied to the cascading group of all CSS tutorial properties for the element. It is window.getComputedStyle () only for IE substitution.

Type: String. Status: Writable.

Dir
Specify the dir attribute of the element, which declares the direction of the document text.

Type: String. Status: Writable.

Id
Specify the id attribute of the element. In a document, no two elements have the same ID value.

Type: String. Status: Writable.

innerHTML
Sets the string that the element contains, excluding the start and end tags of the element itself. Querying this property returns the contents of the element as an HTML text string. Set this property to an HTML text string, you can replace the element's content with an HTML parsing representation. This property cannot be set when the document is loaded. This non-standard attribute, derived from IE4, has been supported by all modern browsers.

Type: String. Status: Writable.

Lang
Specify the lang attribute of the element, which declares the language code of the element's content.

Type: String. Status: Writable.

Offsetheight, offsetwidth
Returns the height and width of the element, in pixels. This is a nonstandard but well supported attribute.

Type: Int. Status: Read Only.

Offsetleft
Returns the offset, in pixels, of the left edge of the current element to the left edge of its containing element.

Type: Int. Status: Read Only.

offsettop
Returns the offset, in pixels, of the top boundary of the current element to the top boundary of its containing element.

Type: Int. Status: Read Only.

offsetparent
Returns a reference to the containing element of the most recent dynamic location, all of which are determined by that element. If the element's style.display is set to None, the property returns NULL. This is a nonstandard but well supported attribute.

Type: node. Status: Read Only.

ScrollHeight, ScrollWidth
Returns the full height and width of the element, in pixels. When an element has a scroll bar (for example, due to the overflow property of CSS), these properties and offsetheight differ from offsetwidth, and offsetheight and offsetwidth only report the size of the visible part of the element. This is a nonstandard but well supported attribute.

Type: Int. Status: Read Only.

ScrollTop, ScrollLeft
Returns the number of pixels that have scrolled to the left or top edge of the element. These pixels are useful only if the element has a scroll bar, for example, when the CSS overflow property of the element is set to auto. These properties are also defined only on the <body> or

Type: Int. Status: Read Only.

Style
Returns the value of the style property that sets the inline CSS style for the current element. Note that the value of this property is not a string.

Type: Css2properties. Status: Read Only.

Title
Specify the title attribute of the element. When the mouse hovers over the element, many browsers display the value of this property in the element's ToolTip.

Type: String. Status: Writable.

Commonly used in three kinds of

XML DOM reference manual: Document Object

XML DOM Reference manual: document.getElementById ()

XML DOM Reference manual: document.getElementsByTagName ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.