PDA

View Full Version : Trouble with Script!!


RosalindD
12-22-2002, 10:40 AM
I'm having a major problem trying to write a certain script. I'm trying to write a script that looks through the elements in an XHTML page and places enclosing 'strong' tags around all text inside all paragraph elements. Closing tags as well. I know that i have to use the innerText property, but I have no idea how. Right now it only works on the first line of the innerText, but only if I put a class ID on the paragraph. If I do it to all the other paragraphs, it doesn't work. Someone please help me as soon as possible! :confused:

Skyzyx
12-22-2002, 03:24 PM
Well, first of all, I believe that <STRONG> was depreciated in HTML 4.01, and is obsolete in XHTML 1.0 (I think... JKD, can you verify this?). What you'll probably want to do is use <b> or <span style="font-weight:bold;"> to bold something like <STRONG> used to.

Also, I have to assume that when you said "Paragraph Tags" you meant <p>.

With that in mind, I'd try something like this:

pGet=document.getElementsByTagName('p');
pLen=pGet.length;

for (i=0; i<=pLen; i++)
{
pGet[i].innerText='<b>'+pGet[i].innerText+'</b>';
}


Hope this helps!

Mr J
12-22-2002, 03:37 PM
I think you have to use innerHTML otherwise the tags are shown with the text


pGet=document.getElementsByTagName('p');
pLen=pGet.length;
for (i=0; i<pLen; i++){
pGet[i].innerHTML='<b>'+pGet[i].innerText+'</b>';
}

Skyzyx
12-22-2002, 04:28 PM
You're right... thank you for the correction.