mychel_normandeau
asked on
onclick on an image within a td fires the tr onclick event too
I have an image in a <td>. This image have an onclick javascript event.
My problem is that the <tr> where the <td> is also have an onclick event. When I click the image, the onclick of the <tr> also fires.
How can I block the <tr> onclick when I click the <td> image ?
My problem is that the <tr> where the <td> is also have an onclick event. When I click the image, the onclick of the <tr> also fires.
How can I block the <tr> onclick when I click the <td> image ?
mychel_normandeau,
In the onclick event in the image tag try to add "return false." For example ...
onclick="theFunction(); return false;"
This may depend on the browser and how it handles the events but using return false will stop other default behavior after the script.
Let me know if you have any questions or need more information.
b0lsc0tt
In the onclick event in the image tag try to add "return false." For example ...
onclick="theFunction(); return false;"
This may depend on the browser and how it handles the events but using return false will stop other default behavior after the script.
Let me know if you have any questions or need more information.
b0lsc0tt
ASKER
raj3060: I can't have only one click since a <tr> click put my row in "edit mode" (i change normal text to <input> with DOM) and the image click within the last <td> deletes the current row (with DOM/AJAX)...
b0lsc0tt: I tried the return false without success :(
b0lsc0tt: I tried the return false without success :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just out of curiousity, how does one click a TR without clicking a TD?
Badotz, are you asking me and are you serious? The asker actually had an image tag in this and it has the onclick event but I'll be happy to talk about bubbling, etc if you are interested. A new question would be nice though if you are really curious about this.
bol
bol
The asker said, "My problem is that the <tr> where the <td> is also have an onclick event." Hence my question (to no one in particular) about clicking a TR. Not a word was said about an IMG tag...
Not a word by me, that is...
Badotz,
From the question body ...
"I have an image in a <td>. This image have an onclick javascript event."
Maybe I have misread it but I understood there was an image tag too and the onclick was in it. Hopefully the asker will clarify this but it may not make a big deal for his question.
I don't mind addressing your question too but just wasn't sure if you were serious or asking me. Also, I guess I didn't completely understand what real question was either. If you have a question along those lines and are interested in my response then feel free to open a new question and post its URL here in a comment. I think there is info to answer what you ask in the Quirksmode page I linked above but I'll be happy to try to add my own comments too.
bol
From the question body ...
"I have an image in a <td>. This image have an onclick javascript event."
Maybe I have misread it but I understood there was an image tag too and the onclick was in it. Hopefully the asker will clarify this but it may not make a big deal for his question.
I don't mind addressing your question too but just wasn't sure if you were serious or asking me. Also, I guess I didn't completely understand what real question was either. If you have a question along those lines and are interested in my response then feel free to open a new question and post its URL here in a comment. I think there is info to answer what you ask in the Quirksmode page I linked above but I'll be happy to try to add my own comments too.
bol
ASKER
"how does one click a TR without clicking a TD"
TR OnClick always fires when you click anything on it's child nodes (TD, or TD's content). In my case an image within a TD had a OnClick event too and dind't wanted the TR OnClick ti fire. b0lsc0tt solution solved it.
TR OnClick always fires when you click anything on it's child nodes (TD, or TD's content). In my case an image within a TD had a OnClick event too and dind't wanted the TR OnClick ti fire. b0lsc0tt solution solved it.
I'm glad I could help. Thanks for the grade, the points and the fun question.
bol
bol
Have one onclick.