
03-15-2008, 06:56 AM
|
 |
Tachikoma
|
|
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,594
|
|
Javascript: Get position of click in HTML
|
Ref: XHTML / Javascript: Advanced text editor
Hi. Ive spent all night working on this and im starting to get a basic idea of what to do so now i have a more specific question.
When i click on the div that im using to represent a textbox i get the X and Y position of the click
Code:
function getXPos(e){
return e.pageX || (e.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft));
}
function getYPos(e){
return e.pageY || (e.clientY+(document.documentElement.scrollTop || document.body.scrollTop));
}
function editor_onClick(e){
var editor=SPKGetObject('editor');
clickX=getXPos(e)-editor.offsetLeft;
clickY=getYPos(e)-editor.offsetTop;
}
How do i detect which span was clicked in? Would it make more sense to attach an event to every span or can it be done by looping through each span in the div?
I plan to have every bit of text inside a span but not have any span inside another span
|
|