473,699 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.mozil la.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 14652
[posted and mailed]

Andrew Poulos <ap*****@hotmai l.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.mozil la.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.getEle mentById(divID) ;
if (divEl) {
divEl.innerHTML = "<strong>No w</strong> this is really cool!!!";
}
}
</script>
<body>
<div id="divMyConten ts">
blah blah blah<br>
<a href="javascrip t:changeMe('div MyContents')>Ch ange 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.getSelec tion.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
11054
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 SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value...
2
4274
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 it so that the first item shows the words "Most Recent" instead of the date. I've tried setting the SelectedItem, Text, and SelectedText of the list box to "Most Recent", when the SelectedIndex changes to 0, but nothing happens.
7
2966
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 already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
4
19621
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
1746
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 correctly but not the text. Thanks Desired end result: <select id="selectBox" multiple="multiple" size="4"> <option value="Div3">About the Company</option> <option value="Div1">Ratings</option>
2
2018
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 of the group that will receive the e-mail. I pass this.form to a function to validate the other data before handing it off to a script to actually do the mailing. The mailer script looks at all of the form's fields and sends their names and...
1
3037
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 the first change (UP only) but after that the last element in the list disappears :( I have no idea why this is happening so could anyone offer a solution or a better method of doing the above task? Thanks in advance <html>
3
1582
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 match the field headers for the selected table. It also hides any text boxes that are surplus to the number of fields of the selected table. The user can then add their search criteria into the text boxes and search the selected table. To achieve...
4
7803
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 this !if any example is there this would help me a lot as i am not gud in javascript!
0
8700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9184
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9048
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8931
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8892
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7767
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6539
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4635
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.