?
Solved

loop and P elements

Posted on 2003-03-10
6
Medium Priority
?
313 Views
Last Modified: 2013-11-19
hi, i need help.... i need to write a script that loops through the elements in a page and places enclosing <STRONG>...</strong> tags around all text inside all P elements.  
0
Comment
Question by:speedlight24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 8104880
<jAy>

Try this link
http://www.w3schools.com/js/js_looping.asp

</jAY>
0
 
LVL 5

Accepted Solution

by:
JimV_ATL earned 80 total points
ID: 8105523
Here's a javascript function which sets the style of a given tag.  I followed it by several examples.

<html>
<head>

<script language="javascript">
// Modified from code by Steven Champeon found at
// http://developer.apple.com/internet/_javascript/styles.html
// setStyleByTag: given an element type, style property and
// value, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
function setStyleByTag(e, p, v) {
          var elements = document.getElementsByTagName(e);
          for(var i = 0; i < elements.length; i++) {
               elements.item(i).style[p] = v;
          }
     }
</script>

     <title>Untitled</title>
</head>

<body>
<p>test</p>


<a href="javascript:setStyleByTag('P','fontWeight','bold')">Make Bold</a><br>
<a href="javascript:setStyleByTag('P','fontWeight','normal')">Return Font-Weight</a><br>
<a href="javascript:setStyleByTag('P','color','blue')">Make Blue</a><br>
<a href="javascript:setStyleByTag('P','color','')">Return Color</a><br>
<a href="javascript:setStyleByTag('P','fontStyle','Italic')">Make Italics</a><br>
<a href="javascript:setStyleByTag('P','fontStyle','Normal')">Return Font-Style</a><br>
</body>
</html>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10113504
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: JimV_ATL {http:#8105523}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
 

Expert Comment

by:lilianabalcazar
ID: 14997109
This is my answer:

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Fig 13.2: all.html       -->
<!-- Using the all collection -->

<html xmlns = "http://www.w3.org/1999/xhtml">
   <head>
      <title>Object Model</title>

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

         function start()
         {
            for ( var loop = 0; loop < document.all.length; ++loop )
               elements += "</strong>" + document.all[ loop ].tagName;

            pText.innerHTML += elements;
            alert( elements );
         }
         // -->
      </script>
   </head>

   <body onload = "start()">
      <p id = "pText">Elements on this Web page:</p>
   </body>
</html>
0
 

Expert Comment

by:lilianabalcazar
ID: 14997155
I want to make a correction on the script section:

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

         function start()
         {
            for ( var loop = 0; loop < document.all.length; ++loop )
               elements += "<strong>" + document.all[ loop ].tagName + "</strong>";

            <!-- pText.innerHTML += elements; --!>
            alert( elements );
         }
         // -->
      </script>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question