Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

javascript - How to get event target's parent with jQuery?

I use jQuery's event object to get the target's parent. The code is:

event.target.parentElement

In Chrome it works, but in Firefox, it doesn't. I use alert() to print the output.

event.target is an URL in both Chrome and Firefox; but event.target.parentElement in Chrome is [Element object], and in Firefox it is null.

What should I do to solve this problem? I still wonder if IE will have this problem?

Thanks.

question from:https://stackoverflow.com/questions/9766171/how-to-get-event-targets-parent-with-jquery

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To access the parent, you could do:


var par = $(event.target).parent();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...