Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Can we know which html clicked by user.
Posted

1 solution

Sounds like a wrong approach. You don't need to know which one is clicked, you need to handle the click differently depending on what the use clicks. Do you see the difference?

So, you just install some handler for some elements, some different handler for other elements:
JavaScript
function someClickHandler() {
   // do something
}
function someOtherHandler() {
   // do something else
}

oneElement.onclick = someClickHandler;

anotherElement.onclick = someOtherHandler;
// you can reuse the same handler for more than one element,
// depending on what you need

Additionally, you can pass event object and find the target element using the property target:
JavaScript
// do this little experiment:

oneElement.onclick = someClickHandler; // yes, it will work even if the 
// handler is not yet defined; want to know why? :-)
function someClickHandler(ev) {
   if (ev.target === oneElement)
       alert("you passed reference to the element clicked");
}
// use it the way you want


—SA
 
Share this answer
 
v3
Comments
amagitech 16-Mar-15 12:06pm    
My problem is that:
1.My aim is calculating 20 different insurance companies offer. So I did bot. It's clicking and filling txtboxes foreach companies.
2. I am using webbrowser control. I clicked an html element it's work. But when I was compile Invokemember("click") it's not working in this element.
Consequently I want to show that If I click the element by mouse what's happening at background or which element has clicked.
Sergey Alexandrovich Kryukov 16-Mar-15 12:07pm    
Didn't I answer in full? What else is a problem?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900