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

innerHTML Replace Tags

2
I would like to know how I may search for <p> in the body and add <strong>...</strong> around each paragraph found.

This is the script I have to handle the loop/search but I am not sure how to insert the strong tags.

Thanks.

<script type = "text/javascript">
<!--
var elements = "";

function start()
{
for ( var loop = 0; loop < document.all.length; loop++ )
if (document.all[loop].tagNam e == "p" )
document.all[loop].innerHTML= ?????
Mar 8 '07 #1
3 3161
iam_clint
1,208 Expert 1GB
don't use document.all
use document.getElementsByTagName("P")

example
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body onload="pstrong();">
  3. <script>
  4. function pstrong() {
  5.   var elems = document.getElementsByTagName("P");
  6.   for (i=0; i<elems.length; i++) {
  7.     elems[i].innerHTML = "<strong>"+elems[i].innerHTML+"</strong>";
  8.   }
  9. }
  10. </script>
  11. <p> this is an example</p>
  12. of something
  13. <p>fantastic</p>
  14. </body>
  15. </html>
  16.  
heres a sample i made
Mar 8 '07 #2
mrhoo
428 256MB
Unless you have a reason for the strong tags, why not use css to style your paragraphs?

p{font-weight:bold;line-height:1.2}
Mar 8 '07 #3
iwujay
2
Thank you very much.

Jay

don't use document.all
use document.getElementsByTagName("P")

example
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body onload="pstrong();">
  3. <script>
  4. function pstrong() {
  5.   var elems = document.getElementsByTagName("P");
  6.   for (i=0; i<elems.length; i++) {
  7.     elems[i].innerHTML = "<strong>"+elems[i].innerHTML+"</strong>";
  8.   }
  9. }
  10. </script>
  11. <p> this is an example</p>
  12. of something
  13. <p>fantastic</p>
  14. </body>
  15. </html>
  16.  
heres a sample i made
Mar 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Soren Vejrum | last post by:
I am working on a web-based html editor using MSIE's designmode and iframes. Everything works just fine, but MSIE changes all my relative "a href" and "img src" links (i.e. "/index.asp") to...
6
by: Tim Fooy | last post by:
Hi all, I have the following problem. In my page i have a large <div> with tags inside it that have event handlers on them (onclick etc.). When i run div.innerHTML = moreText + div.innerHTML,...
10
by: oopaevah | last post by:
When using innerHTML to insert xhtml IE5+ mangles the xhtml completely. For example it removes the quotes from attributes. It also does other ridiculous things like on a <div> it will insert the...
4
by: bissatch | last post by:
Hi, I have the following simple HTML page. I am trying to get the innerHTML of the table element, "xmltable". I do intend to change the innerHTML of this table but at this stage I am having...
7
by: Hoss | last post by:
Hello all- This is what im trying to achieve. At the top of my page there is some search functionality, through which you cause to be loaded a string representing an HTML page. Below this and...
7
by: bobd314 | last post by:
Currently, I am having a problem replacing the value of a input box with something else using the innerHTML thing. Right now I have something going <script type="text/javascript"><!-- function...
3
by: e271828 | last post by:
I've got a way to get all of the source HTML for a given page by line and detect where certain attributes exist, and I would like to write the line of HTML code I've been working on into a new...
2
by: xhe | last post by:
I met a very headache problem in javascript, I think this might be difference between IE and NS / Safari. I have a text area <form> <textarea name='tex1' onkeyup='displayit();'></textarea>...
15
by: rage3324 | last post by:
I am posting html onto my main page between div tags using xmlhttprequest and innerhtml. The html I am posting has javascript inside which I am executing using the eval() function. However, the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.