JS gets the ID and attributes of the HTML element where the mouse is located

Source: Internet
Author: User

JS gets the ID and attributes of the HTML element where the mouse is located:

Code:
  1. <Div onclick = "get_srcelement ()">
  2. <Div id = "001" style = "border: 1px solid red; width: 100%; Height: 500px"> <span id = "node001"> This is the 1st node div001 <span>
  3. <Div id = "002" style = "border: 1px solid red; width: 80%; Height: 300px"> <span id = "node002"> This is the 2nd node div002 <span>
  4. <Div id = "003" style = "border: 1px solid red; width: 50%; height: 200px"> <span id = "node003"> This is the 3rd node div003 <span>
  5. </Div>
  6. <Div id = "004" style = "border: 1px solid red; width: 50%; height: 200px"> <span id = "node003"> This is the 3rd node div004 <span>
  7. </Div>
  8. </Div>
  9. </Div>
  10. <Script>
  11. Function Get_srcElement ()
  12. {
  13. Var srcElement = ""
  14. SrcElement = srcElement + "\ n" + "event. srcElement. id:" + event. srcElement. id
  15. Srcelement = srcelement + "\ n" + "event. srcelement. Children [0]. tagname:" + event. srcelement. Children [0]. tagname
  16. Srcelement = srcelement + "\ n" + "event. srcelement. firstchild. ID:" + event. srcelement. firstchild. ID
  17. Srcelement = srcelement + "\ n" + "event. srcelement. lastchild. ID:" + event. srcelement. lastchild. ID
  18. Alert (srcelement)
  19. }
  20. </SCRIPT>
  21. </Div>
  22. <Div id = "div_001">
  23. <Form ID = "form_001">
  24. <Input type = "button" id = "button_001_id" name = "button_001_name" value = "click to view" class = "button_000000class" onclick = "get_srcelement2 (this)">
  25. </Form>
  26. </Div>
  27. <SCRIPT>
  28. Function get_srcelement2 ()
  29. {
  30. VaR srcelement = ""
  31. Srcelement = srcelement + "\ n" + "event. srcelement. ID:" + event. srcelement. ID
  32. Srcelement = srcelement + "\ n" + "event. srcelement. tagname:" + event. srcelement. tagname
  33. Srcelement = srcelement + "\ n" + "event. srcelement. Type:" + event. srcelement. Type
  34. Srcelement = srcelement + "\ n" + "event. srcelement. Value:" + event. srcelement. Value
  35. Srcelement = srcelement + "\ n" + "event. srcelement. Name:" + event. srcelement. Name
  36. Srcelement = srcelement + "\ n" + "event. srcelement. classname:" + event. srcelement. classname
  37. Srcelement = srcelement + "\ n" + "event. srcelement. parentelement. ID:" + event. srcelement. parentelement. ID
  38. Srcelement = srcelement + "\ n" + "event. srcelement. getattribute:" + event. srcelement. getattribute
  39. Alert (srcelement)
  40. }
  41. </SCRIPT>

Currently, Firefox is not compatible with Firefox. Refer to the code below to see if it is feasible. I have time to modify this log.

Function get_srcelement (E)
{
EE = Window. Event | E;
VaR tmpobj = ee. srcelement | ee.tar get;
VaR srcelement = srcelement + "" + "event. srcelement. ID:" + tmpobj. ID
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.