How to change what is inside a tag

O

Oxnard

if I have some text inside a tag like:

<div id="test" >
stuff I want changed
</div>

how can I change it to something else:
<div id="test" >
my new text
</div>

using a javascript fuction which I call elsewhere in the page?
 
R

Randy Webb

Oxnard said:
if I have some text inside a tag like:

<div id="test" >
stuff I want changed
</div>

how can I change it to something else:
<div id="test" >
my new text
</div>

using a javascript fuction which I call elsewhere in the page?

Read the group FAQ, linked in the signature. Especially section 4.15
since it answers that exact question.
 
O

Oxnard

Randy Webb said:
Read the group FAQ, linked in the signature. Especially section 4.15
since it answers that exact question.

I know I *think* I did follow the faq here is the html:

function changeit(myChange)
{ //alert('here ' + myChange);
// status = myChange; document.getElementById("t1").innerHTML = myChange;
}

then in the body of the html:

input type="submit" value="click" onclick="changeit('sds')"
dev id="t1">blah blah</dev

Note: I had to leave off the < & > as Outlook Express wanted to treat it as
html.

for some reason the text 'blah blah' does not change to 'sds'.

I am using IE 6.0.288

Thanks
 
F

Fred Oz

Oxnard said:
function changeit(myChange)
{ //alert('here ' + myChange);
// status = myChange; document.getElementById("t1").innerHTML = myChange;
}

Perhaps you should un-comment some part of the function? Perhaps put:

document.getElementById("t1").innerHTML = myChange;

on a line by itself?

It's not good style to put multiple statements on the same line, it's
far better to put one statement per line to make the code more
readable, so your function would become (with debug comments intact):

function changeit(myChange){
//alert('here ' + myChange);
// status = myChange;
document.getElementById("t1").innerHTML = myChange;
}

Also read the thread below: "Changing <p> text on the fly".

Fred.
 
O

Oxnard

Fred Oz said:
Perhaps you should un-comment some part of the function? Perhaps put:

document.getElementById("t1").innerHTML = myChange;

on a line by itself?

It's not good style to put multiple statements on the same line, it's
far better to put one statement per line to make the code more
readable, so your function would become (with debug comments intact):

function changeit(myChange){
//alert('here ' + myChange);
// status = myChange;
document.getElementById("t1").innerHTML = myChange;
}

Also read the thread below: "Changing <p> text on the fly".

Fred.

the text did not format quite right in OE. The statement:
document.getElementById("t1").innerHTML = myChange;
was on a line by itself.
I remove the commented out lines:

function changeit(myChange){
document.getElementById("t1").innerHTML = myChange;
}

this did not work.
If I put the line:
alert('myChange ' + myChange);
as the first line in the function I see what I am passing to the function,
however if I put it after the innerHTML line the dialog box never appears.
It seems I see an error on status message in IE but it goes by quickly. How
can I see what the error is?
 
F

Fred Oz

Oxnard wrote:
[snip]
then in the body of the html:

input type="submit" value="click" onclick="changeit('sds')"
dev id="t1">blah blah</dev
[snip]

this did not work.

Perhaps because you have a <dev> tag, not a <div> tag. Firefox will
tolerate the <dev> tag in quirks mode, IE does not.

Fred.
 
O

Oxnard

Fred Oz said:
Oxnard wrote:
[snip]
then in the body of the html:

input type="submit" value="click" onclick="changeit('sds')"
dev id="t1">blah blah</dev
[snip]

this did not work.

Perhaps because you have a <dev> tag, not a <div> tag. Firefox will
tolerate the <dev> tag in quirks mode, IE does not.

Fred.

After taken a break I got it. Additioning I missed putting a closing > else
where in the page.
Thank you for your time.
 

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

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top