473,545 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing <div> or <p> contents with link clicks

Hi,

What I'm trying (quite poorly) to do is make it so when a link is clicked the
text inside a div or p changes.

I've tried numerous things, most of which work in IE but none of which work in
gecko browsers e.g. Mozilla, Netscape, Epiphany etc etc.

This is what I have now and works fine in IE but sits there doing nothing in
anything else:

<script type="text/javascript">
function changeText()
{
document.all.di v_or_p_id.inner Text = "blahblah";
}
</script>

Can anybody help me with this?

Thanks,
Craig.
Jul 20 '05 #1
3 2215
DU
Craig wrote:
Hi,

What I'm trying (quite poorly) to do is make it so when a link is
clicked the text inside a div or p changes.

When a link is clicked, a new document should be loaded. Otherwise,
you're misusing an element for a particular javascript execution and
users of your page will be confused (and so will the browser properties).
Best is to use a button for such goal and not a link.
I've tried numerous things, most of which work in IE but none of which
work in gecko browsers e.g. Mozilla, Netscape, Epiphany etc etc.

This is what I have now and works fine in IE but sits there doing
nothing in anything else:

<script type="text/javascript">
function changeText()
{
document.all.di v_or_p_id.inner Text = "blahblah";
innerText is a proprietary MSIE attribute, not part of W3C web standards.
}
</script>

Can anybody help me with this?

Thanks,
Craig.

Assuming this is your text:

<p id="idTargetedP arg">Previous text to change</p>
<p><button type="button" onclick="change Text();">Change the text in the
above paragraph</button></p>

then
<script type="text/javascript">
function changeText()
{
if(document.get ElementById("id TargetedParg"). childNodes[0].nodeType == "3")
{
document.getEle mentById("idTar getedParg").chi ldNodes[0].nodeValue = "New
text replacement";
};
this.disabled = true;
}
</script>

The text node must be the first node of the targeted paragraph. This
will work in MSIE 6 for windows, Opera 7.x, in any Mozilla 1.x based
browsers and in other W3C DOM 2 CharacterData compliant browsers.

All other W3C DOM 2 CharacterData attributes and methods are entirely
supported by MSIE 6, Mozilla 1.x, Opera 7 and other compliant browsers.
There is no need, no justification to use innerText anymore.

DU

Jul 20 '05 #2
That works a treat, thank you very much. Is there a way to change it to text
including HTML e.g. the equivalent to MSIE's document.all.di v_or_p_id.inner HTML?

Thanks again,
Craig

DU wrote:
Craig wrote:
Hi,

What I'm trying (quite poorly) to do is make it so when a link is
clicked the text inside a div or p changes.


When a link is clicked, a new document should be loaded. Otherwise,
you're misusing an element for a particular javascript execution and
users of your page will be confused (and so will the browser properties).
Best is to use a button for such goal and not a link.
I've tried numerous things, most of which work in IE but none of which
work in gecko browsers e.g. Mozilla, Netscape, Epiphany etc etc.

This is what I have now and works fine in IE but sits there doing
nothing in anything else:

<script type="text/javascript">
function changeText()
{
document.all.di v_or_p_id.inner Text = "blahblah";

innerText is a proprietary MSIE attribute, not part of W3C web standards.
}
</script>

Can anybody help me with this?

Thanks,
Craig.


Assuming this is your text:

<p id="idTargetedP arg">Previous text to change</p>
<p><button type="button" onclick="change Text();">Change the text in the
above paragraph</button></p>

then
<script type="text/javascript">
function changeText()
{
if(document.get ElementById("id TargetedParg"). childNodes[0].nodeType == "3")
{ document.getEle mentById("idTar getedParg").chi ldNodes[0].nodeValue =
"New text replacement";
};
this.disabled = true;
}
</script>

The text node must be the first node of the targeted paragraph. This
will work in MSIE 6 for windows, Opera 7.x, in any Mozilla 1.x based
browsers and in other W3C DOM 2 CharacterData compliant browsers.

All other W3C DOM 2 CharacterData attributes and methods are entirely
supported by MSIE 6, Mozilla 1.x, Opera 7 and other compliant browsers.
There is no need, no justification to use innerText anymore.

DU

Jul 20 '05 #3
DU
Craig wrote:
That works a treat, thank you very much. Is there a way to change it to
text including HTML e.g. the equivalent to MSIE's
document.all.di v_or_p_id.inner HTML?

Thanks again,
Craig

Best would have been for you to give/follow up with a complete chunk of
code as a working example or an url with an example here. I strongly
recommend you drop completely recourse to
document.all
when constructing a DHTML command or javascript instruction for the sake
of interoperabilit y and cross-browser support. document.all is not a W3C
DOM method; it's a MSIE-only proprietary DOM method which will not work
in all browsers.

These 2 documents:

Using Web Standards in Your Web Pages
http://www.mozilla.org/docs/web-deve...upgrade_2.html

Updating DHTML Web Pages for next generation browsers:
What you need to know about the layer tag, document.all, and other
proprietary extensions and how to work with them in a cross browser world.
http://devedge.netscape.com/viewsour...tml-web-pages/

explain well involved issues.

FWIW,
document.getEle mentById("div_o r_p_id").innerH TML = "<b>Very
important<\/b> notice.";
will work in MSIE 6, Opera 7, NS 7.x, Mozilla 1.x, K-meleon 0.8.x,
MyIE2, etc.

DU
DU wrote:
Craig wrote:
Hi,

What I'm trying (quite poorly) to do is make it so when a link is
clicked the text inside a div or p changes.


When a link is clicked, a new document should be loaded. Otherwise,
you're misusing an element for a particular javascript execution and
users of your page will be confused (and so will the browser properties).
Best is to use a button for such goal and not a link.
I've tried numerous things, most of which work in IE but none of
which work in gecko browsers e.g. Mozilla, Netscape, Epiphany etc etc.

This is what I have now and works fine in IE but sits there doing
nothing in anything else:

<script type="text/javascript">
function changeText()
{
document.all.di v_or_p_id.inner Text = "blahblah";


innerText is a proprietary MSIE attribute, not part of W3C web standards.
}
</script>

Can anybody help me with this?

Thanks,
Craig.



Assuming this is your text:

<p id="idTargetedP arg">Previous text to change</p>
<p><button type="button" onclick="change Text();">Change the text in
the above paragraph</button></p>

then
<script type="text/javascript">
function changeText()
{
if(document.get ElementById("id TargetedParg"). childNodes[0].nodeType ==
"3")
{ document.getEle mentById("idTar getedParg").chi ldNodes[0].nodeValue =
"New text replacement";
};
this.disabled = true;
}
</script>

The text node must be the first node of the targeted paragraph. This
will work in MSIE 6 for windows, Opera 7.x, in any Mozilla 1.x based
browsers and in other W3C DOM 2 CharacterData compliant browsers.

All other W3C DOM 2 CharacterData attributes and methods are entirely
supported by MSIE 6, Mozilla 1.x, Opera 7 and other compliant
browsers. There is no need, no justification to use innerText anymore.

DU

Jul 20 '05 #4

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

Similar topics

0
688
by: Lilou | last post by:
Hello this page works : http://lilou.leuwen.chez.tiscali.fr/testlilou.htm the source : .... a.link:hover div.test2 {display : block; position: absolute; z-index: 1000;
3
5001
by: Philip | last post by:
I am trying to make a bunched of left-floated divs that will be contained in a larger div. the floated divs all contain a left-floated img and text of varying sizes. If I don't set a height (or height:auto) the larger div doesn't seem to see the nested divs, and they spill out the bottom. IE seems to automatically resize the larger div as...
15
2235
by: scott | last post by:
Hello, I'm working on updating some of my table-based sites to use CSS instead of tables. One of my sites has a header that is composed of three elements: A B C In my prior design, this was done using a table. A, B, and C were each <tdelements.
3
1969
by: chris1606 | last post by:
I have an image gallery that pops up an enlarged version of a picture when someone clicks on it. That bit works, but it should also load the picture's caption into the floating layer. Instead the caption remains unchanged and gives an "object doesn't support this property or method" dialog. The code is as follows: <script> function...
2
3365
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given field(s). The popping-up seems to work just fine; it's the tearing down that's giving me grief. If I stick a onmouseout event on the same input field...
8
1863
by: richard | last post by:
I have <div id=box1 style="display:block"as the initial setting. I need to change the "display:block" to "display:none" then back to "display:block" as a means of clearing anything that might be displayed within the box1 division. What's the simplest way of doing this?
0
1841
by: Patricia Mindanao | last post by:
Assume I have a HTML web page with a pre-defined <div...</divarea. When the users clicks now on a certain link on this web page (outside or inside this "div" area) then the content of a file say "first.html" (currently still on the server) should be loaded and filled into the existing <div>...</divarea in the current Web page and displayed. ...
8
10021
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a...
0
7411
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7669
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. ...
0
7926
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...
1
7439
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...
0
7773
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...
0
4962
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
722
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...

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.