page level onclick - can I detect nearest word

J

Jeremy J Starcher

That's easy if you can prepare the target text:

http://jorgechamorro.com/cljs/050/

This is close to the approach I was suggesting, but you should parse out
the text nodes and turn them into spans instead of building the page via
Javascript. That way, Javascript disabled browsers will get a limited
functionality instead of none-what-so-ever.
 
D

David Mark

You ought to wrap each single word in a single htmlElement because the
target of a click event is an element.

He ought to do nothing of the sort. Clicking text is like selecting
zero characters. As Martin mentioned, a proper solution involves text
ranges. Unfortunately, due to IE's proprietary implementation, a
cross-browser solution is difficult (though definitely not
impossible.)
 
J

Jorge

He ought to do nothing of the sort.  Clicking text is like selecting
zero characters.  As Martin mentioned, a proper solution involves text
ranges.  Unfortunately, due to IE's proprietary implementation, a
cross-browser solution is difficult (though definitely not
impossible.)

He does not want to *select* anything. He wants to know the word that
the user has clicked on. AFAIK, the best way to handle that with ease
is to wrap each word in an element. Either beforehand at the server
side or later on at the client side. If that's not a proper cross-
browser solution, please let me know why and what's the proper way.
 
D

David Mark

He does not want to *select* anything. He wants to know the word that

Who said he did?
the user has clicked on. AFAIK, the best way to handle that with ease
Clicked.

is to wrap each word in an element. Either beforehand at the server
side or later on at the client side. If that's not a proper cross-
browser solution, please let me know why and what's the proper way.

It isn't because it is a ludicrous end-around. And as mentioned twice
now, you use text ranges. If you had read my comment about clicking
text as something other than a brain-teaser, you would have a good
foundation to start.

RTFM, STFW, etc. It worked for me. :)
 
P

p7eregex

He does not want to *select* anything. He wants to know the word that
the user has clicked on. AFAIK, the best way to handle that with ease
is to wrap each word in an element. Either beforehand at the server
side or later on at the client side. If that's not a proper cross-
browser solution, please let me know why and what's the proper way.

By the way, lets say that in editable page mode, I do indeed wrap each
word in an element. And the user selects a range of words and then
clicks. Will my event handler be able to detect each word in the
range as being a target of the click?

Andy
 
D

David Mark

By the way, lets say that in editable page mode, I do indeed wrap each
word in an element.

That would be a very backwards thing to do.
And the user selects a range of words and then
clicks.  Will my event handler be able to detect each word in the
range as being a target of the click?

Not through any sort of help from extraneous elements. All they will
do is get in the way.

https://developer.mozilla.org/En/DOM/Selection

http://msdn.microsoft.com/en-us/library/ms535869(VS.85).aspx
 
A

Andy

He does not want to *select* anything. He wants to know the word that
the user has clicked on. AFAIK, the best way to handle that with ease
is to wrap each word in an element. Either beforehand at the server
side or later on at the client side. If that's not a proper cross-
browser solution, please let me know why and what's the proper way.

Jorge,

Can you suggest what I might do if the document that I'm munging
already contains a large <span> range? How can I wrap an individual
word then? Using <a>?

Andy
 
D

David Mark

Jorge,

Can you suggest what I might do if the document that I'm munging
already contains a large <span> range?  How can I wrap an individual
word then?  Using <a>?

Why are you asking somebody who doesn't have the solution for further
information about his non-solution? Doesn't seem like a strategy that
will bear fruit.
 
A

Andy

Why are you asking somebody who doesn't have the solution for further
information about his non-solution?  Doesn't seem like a strategy that
will bear fruit.

David,

Can you elaborate on the best solution. I checked your previous posts
and saw that you were talking about text ranges. But when you click a
text range, it disappears.

Andy
 
D

David Mark

David,

Can you elaborate on the best solution.  I checked your previous posts
and saw that you were talking about text ranges.  But when you click a
text range, it disappears.

They certainly do not disappear as they are not visible. You are
jumping the gun on those. See the links I posted (they point to
information on selections, not text ranges.)
 
J

Jorge

Jorge,

Can you suggest what I might do if the document that I'm munging
already contains a large <span> range?

Can you post an example, or is it online somewhere ?
 How can I wrap an individual word then?  Using <a> ?

No, just wrap them in more spans, nested <span>s are ok.
 
J

Jorge

Why are you asking somebody who doesn't have the solution for further
information about his non-solution?  Doesn't seem like a strategy that
will bear fruit.

We'll see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,646
Members
47,254
Latest member
GayMilline

Latest Threads

Top