tblack1100
asked on
How to identify SPAN at cursor position
Using client-side javascript and dhmtl, how would I determine which SPAN is the container for the text at the current cursor position. Since the SPAN tag is not a form control, onfocus and onkeydown events arent available. I have tried to get the window.event srcElement.id in the onkeydown event of the body object, but it returns the editor control and not the SPAN object in the edit control.
I would appreciate any help you could provide.
Thanks,
Tim Black
I would appreciate any help you could provide.
Thanks,
Tim Black
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Show some code please.
So you have a span inside of an input?
So you have a span inside of an input?
ASKER
Basically, I have a 3rd-party html editor control (CuteSoft's htmledit) and when a button is clicked, it places the text I type in a SPAN. The onmouseover/onmouseout events change the background color of the SPAN as the mouse cursor move over and away from the text in the SPAN. I want the same effect when I move into and out of the text area with keystrokes.
Thanks,
Tim
Thanks,
Tim
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or this?
<input type=text value="Click on me and Press Tab">
<span style="width:100;backgroun d-color:pi nk;" contenteditable id=span1
onmouseover="this.style.ba ckgroundCo lor='yello w';"
onfocus="this.style.backgr oundColor= 'yellow';"
onmouseout="this.style.bac kgroundCol or='pink'; "
onblur="this.style.backgro undColor=' pink';"
>
span 1</span>
<input type=text value="Click on me and Press Tab">
<span style="width:100;backgroun
onmouseover="this.style.ba
onfocus="this.style.backgr
onmouseout="this.style.bac
onblur="this.style.backgro
>
span 1</span>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I object, given that many in here have given valuable advice, myself included. I may not have written the code for the original poster, but I have offered three viable methods to accomplish the goal.
ASKER