speedlight24
asked on
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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>
<?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>
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>
<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>
Try this link
http://www.w3schools.com/js/js_looping.asp
</jAY>