Event. srcelement event.tar get attribute

Source: Internet
Author: User

IE event. srcelement

FF event.tar get

VaR OBJ = event. srcelement? Event. srcelement: event.tar get;

 

1. event. srcelement. parentnode. tagname;
Obtain the label name of the previous node.
Eg:
<Div style = "border: 10px red solid">
<Input type = "button" value = "parent element tag" onclick = "alert (event. srcelement. parentnode. tagname)">
</Div>

Child and parent tags of event. srcelement:

The first sub-tag is
Event. srcelement. firstchild
The last one is
Event. srcelement. lastchild
You can also use
Event. srcelement. Children [I]
Event. srcelement. childnode [I]
As for event. srcelement. parentelement, it refers to the previous object of the object where the mouse is located.

2. event. srcelement. tagname to get the Tag Name of the clicked position

3. event. srcelement. parentelement. Title

Eg:
<Table border = 1 width = "200">
<Tr Title = "Tr test" onclick = "alert (event. srcelement. parentelement. Title)"> <TD> tr </TD> </tr>
</Table>

4. event. srcelement. Title: Obtain the attribute value of the current tag title.

<Table border = 1 width = "200">
<Tr> <TD Title = "TD test" onclick = "alert (event. srcelement. Title)"> TD </TD> </tr>

5. event. srcelement. Options [event. srcelement. selectedindex]. Value

<Select name = "selectname" onchange = "alert (event. srcelement. Options [event. srcelement. selectedindex]. Value)">
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
<Option value = "5"> 5 </option>
</SELECT>
</Table>

Event. srcelement. ID
Event. srcelement. tagname
Event. srcelement. Type
Event. srcelement. Value
Event. srcelement. Name
Event. srcelement. classname
Event. srcelement. parentelement
Event. srcelement. getattribute
Event. srcelement. Children
Event. srcelement. lastchild
Event. srcelement. childnode
Event. srcelement. selectedindex

In short, event. srcelement. value... is commonly used to get the attribute values of money tags.
Event. srcelement. parentelement. Attributes
Event. srcelement. tag attributes
Event. srcelement. parentnode previous Node

 

 

 

JS regards all HTML controls as objects, and operations can be performed through each JS attribute. The overall structure of objects in JS is a tree structure. You can obtain the expected results by tracing at a layer.

Event. srcelement: indicates the current event source.

Event. srcelement. parentnode: the parent node of the current event source.

Parentnode: parent node, that is, the node on the previous layer. Yes

 

Any tag.

 

Event. srcelement. firstchild: The first node of the current event. If the node is input, the input value can be obtained through event. srcelement. firstchild. value.

Event. srcelement. parentelement: refers to the object on which the mouse is located.

Event. srcelement. children: number of objects under the current node. If there are multiple objects, it is an array. For example, if there are two input objects under the current node, you can obtain these two objects using event. srcelement. children [0] and event. srcelement. children [1.

 

Event. srcelement can be seen literally with the following keywords: event, Source

Indicates the source of the current event.

We can call its various attributes, like: Document. getelementbyid ("").

In ie, the event object has the srcelement attribute, but does not have the target attribute. In Firefox, the event object has the target attribute, but does not have the srcelement attribute. However, they play a similar role, namely:

Event. srcelement under event.tar get = IE in Firefox

Solution: Use OBJ (OBJ = event. srcelement? Event. srcelement: event.targettoken used to replace event.tar get under firefox.

In the following situations, the test passes through IE. To test event.tar get under firefox, you can modify and save the code and use Firefox to open the test ):

<Div id = "div_001">
<Form ID = "form_001">
<Input type = "button" id = "button_001_id" name = "button_001_name" value = "click to view" class = "button_000000class" onclick = "get_srcelement (this)">
</Form>
</Div>
<SCRIPT>
Function get_srcelement ()
{
VaR srcelement = ""
Srcelement = srcelement + "\ n" + "event. srcelement. ID:" + event. srcelement. ID
Srcelement = srcelement + "\ n" + "event. srcelement. tagname:" + event. srcelement. tagname
Srcelement = srcelement + "\ n" + "event. srcelement. Type:" + event. srcelement. Type
Srcelement = srcelement + "\ n" + "event. srcelement. Value:" + event. srcelement. Value
Srcelement = srcelement + "\ n" + "event. srcelement. Name:" + event. srcelement. Name
Srcelement = srcelement + "\ n" + "event. srcelement. classname:" + event. srcelement. classname
Srcelement = srcelement + "\ n" + "event. srcelement. parentelement. ID:" + event. srcelement. parentelement. ID
Srcelement = srcelement + "\ n" + "event. srcelement. getattribute:" + event. srcelement. getattribute
Alert (srcelement)
}

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.