Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

loop and P elements

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
speedlight24
Asked:
speedlight24
  • 2
  • 2
1 Solution
 
jaysolomonCommented:
<jAy>

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

</jAY>
0
 
JimV_ATLCommented:
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
 
jaysolomonCommented:
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
 
lilianabalcazarCommented:
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
 
lilianabalcazarCommented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now