Get ID of element that called a function

前端 未结 7 630
梦毁少年i
梦毁少年i 2020-12-07 20:02

How can I get the ID of an element that called a JS function?

body.jpg is an image of a dog as the user points his/her mouse around the screen at different

7条回答
  •  时光取名叫无心
    2020-12-07 20:20

    You can code the handler setup like this:

    
    

    Then this in your handler will refer to the element. Now, I'll offer the caveat that I'm not 100% sure what happens when you've got a handler in an tag, largely because I haven't seen an tag in like a decade or so. I think it should give you the image tag, but that could be wrong.

    edit — yes, it's wrong - you get the tag, not the . So you'll have to get that element's parent (the map), and then find the image that's using it (that is, the whose "usemap" attribute refers to the map's name).

    edit again — except it doesn't matter because you want the area's "id" durr. Sorry for not reading correctly.

提交回复
热议问题