473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Changing selected DIV text

I've managed to get the text a user has selected on a page (in a DIV not
a TEXTAREA) but I don't understand DOM methods well enough to change it.
That it to replace the text with some other text.

I've tried using deleteContents but I couldn't get it to work. And my
experiments with insertNode worked only intermittently.

I've read the relevant sections of developer.mozilla.org but while I
understand what the methods are supposed to do I can't actually get them
to work. Is there some info of a basic nature that explains their usage?

Andrew Poulos
Mar 17 '06 #1
2 14644
[posted and mailed]

Andrew Poulos <ap*****@hotmail.com> wrote in news:441a95be$0$18520
$5*******@per-qv1-newsreader-01.iinet.net.au:
I've managed to get the text a user has selected on a page (in a DIV not a TEXTAREA) but I don't understand DOM methods well enough to change it. That it to replace the text with some other text.

I've tried using deleteContents but I couldn't get it to work. And my
experiments with insertNode worked only intermittently.

I've read the relevant sections of developer.mozilla.org but while I
understand what the methods are supposed to do I can't actually get them to work. Is there some info of a basic nature that explains their usage?
Andrew Poulos


<html>
<script>
function changeMe(divID) {
divEl = document.getElementById(divID);
if (divEl) {
divEl.innerHTML = "<strong>Now</strong> this is really cool!!!";
}
}
</script>
<body>
<div id="divMyContents">
blah blah blah<br>
<a href="javascript:changeMe('divMyContents')>Change Me</a>
</div>
</body>
</html>
Mar 17 '06 #2


Andrew Poulos wrote:
I've managed to get the text a user has selected on a page (in a DIV not
a TEXTAREA) but I don't understand DOM methods well enough to change it.
That it to replace the text with some other text.

I've tried using deleteContents but I couldn't get it to work. And my
experiments with insertNode worked only intermittently.


There is not necessarily some text selected that is part of only a
single text node where it would be clear what replacing the the text
means. So the question is what you wanted to replace if there is e.g. a
selection
<p><strong>Kibo|logy</strong> <em>f</em>o|r all</p>
where | is meant to show the boundary points of the range that forms the
selection. The selection as a text (i.e. window.getSelection.toString())
is 'logy fo' but you then need to decide what to do exactly when you
replace stuff.

If you want to have an example where text is replaced that is all inside
of a single text node then you can check out
<http://home.arcor.de/martin.honnen/mozillaBugs/domLevel2/test2006031702.html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
2
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
4
by: Robert Bravery | last post by:
HI all, In JS, how can I change the selected value of a dropdownlist(select options) I know the value of indexed value of the selected value before it is changed. Thanks Robert
4
by: shankwheat | last post by:
I'm passing a string like 'Div3,Div4' to use as options in a selectbox but I need the text the user sees in the box different from the values. My code populates the values in the selectbox...
2
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name...
1
by: technod | last post by:
Hi, I have constructed a clickable list of words which are added to a select box. I then have buttons to move the added elements up or down in the list. The code below seems to work fine for...
3
by: Darkside12 | last post by:
Hi, I'm trying to build a dynamic query by form. The idea is that a user can select a table in the database via a combo box and this will then change all of the text box labels on the form to...
4
pradeepjain
by: pradeepjain | last post by:
i have a menu of 4 items.all text color is white. and when i click a menu link the other menu items text color should change to black! Is it possible to do with css or javascript help is needed for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.