I've asked my professor about this one a couple of times in email and she gave me some tips but I still can't nail this one down. Our book only gives one example of using .innerHTML and it's not very relevant to this problem so I want to ask you JS proz out there.
We're supposed to loop through the document.all collection and find all the <p> tags and enclose them in <strong> tags. I'm pretty sure I've got most of the script right except for the crucial line where you add the <strong> tags. I've tried a lot of variations but I just don't understand enough about how .innerHTML works to get this right and I can't seem to find it on the Web.
Thanks for any help you can provide. Here's the code...
Expand|Select|Wrap|Line Numbers
- <script type = "text/javascript">
- <!--
- function go() {
- for( var x = 0; x < document.all.length; ++x ) {
- if( document.all[ x ].tagName == "p" ) {
- document.all[ x ].innerHTML = "<strong>" +
- document.all[ x ].innerHTML + "</strong>";
- }
- } //end for
- } //end go
- // -->
- </script>
- </head>
- <body onload = "go()">
- <p>
- This is a sentence that is enclosed in p-tags. It is going to be
- enclosed in strong tags as well once the javascript gets through
- with it. :o)
- </p>
- <p>
- For I am not ashamed of the gospel, for it is the power of God for
- the salvation of all who believe, first for the Jew and then for
- the Gentile.
- </p>
- <p>
- When I'm done with this, I'm going to bed. I'm tired. :o) I watched
- Good Night and Good Luck with my wife tonight. It was interesting.
- I learned a lot about the clash of CBS & Ed Murrow and McCarthy the
- Communist head hunter.
- </p>
- <p style = "font-weight: bold">Here's an example of what bold text should
- look like.</p>
- </body>
- </html>