473,394 Members | 1,718 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,394 software developers and data experts.

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.div_or_p_id.innerText = "blahblah";
}
</script>

Can anybody help me with this?

Thanks,
Craig.
Jul 20 '05 #1
3 2200
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.div_or_p_id.innerText = "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="idTargetedParg">Previous text to change</p>
<p><button type="button" onclick="changeText();">Change the text in the
above paragraph</button></p>

then
<script type="text/javascript">
function changeText()
{
if(document.getElementById("idTargetedParg").child Nodes[0].nodeType == "3")
{
document.getElementById("idTargetedParg").childNod es[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.div_or_p_id.innerHTML?

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.div_or_p_id.innerText = "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="idTargetedParg">Previous text to change</p>
<p><button type="button" onclick="changeText();">Change the text in the
above paragraph</button></p>

then
<script type="text/javascript">
function changeText()
{
if(document.getElementById("idTargetedParg").child Nodes[0].nodeType == "3")
{ document.getElementById("idTargetedParg").childNod es[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.div_or_p_id.innerHTML?

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 interoperability 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.getElementById("div_or_p_id").innerHTML = "<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.div_or_p_id.innerText = "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="idTargetedParg">Previous text to change</p>
<p><button type="button" onclick="changeText();">Change the text in
the above paragraph</button></p>

then
<script type="text/javascript">
function changeText()
{
if(document.getElementById("idTargetedParg").child Nodes[0].nodeType ==
"3")
{ document.getElementById("idTargetedParg").childNod es[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
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
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...
15
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...
3
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...
2
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...
8
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...
0
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.