User Tools

Site Tools


en:web_development:text:javascript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:web_development:text:javascript [2022/02/09 13:44]
mag [Object Notation]
en:web_development:text:javascript [2023/08/16 09:33] (current)
Line 71: Line 71:
   * The order doesn't matter, so let's start with the noun, which will replace 'ball' in the text.   * The order doesn't matter, so let's start with the noun, which will replace 'ball' in the text.
   * Add the following statement below the third comment.   * Add the following statement below the third comment.
-<code>document.getElementsByTagName('span')[1].innerHTML = noun;</code>+<code>document.getElementsByTagName('em')[1].innerHTML = noun;</code>
   * Again, we start with <html>document</html> to indicate we're referring to the HTML code (rather than a variable or object we've created).   * Again, we start with <html>document</html> to indicate we're referring to the HTML code (rather than a variable or object we've created).
   * We need a way of referring to the word 'ball'. Notice that it's already got its own tag <html><em>ball</em></html>. We can use that.   * We need a way of referring to the word 'ball'. Notice that it's already got its own tag <html><em>ball</em></html>. We can use that.
Line 80: Line 80:
   * Finally, we give it the value we obtained from the user in the second step. <html> = noun </html> Notice that <html>noun</html> isn't wrapped in inverted commas because <html>noun</html> isn't text itself. It is the name of a variable that represents text.   * Finally, we give it the value we obtained from the user in the second step. <html> = noun </html> Notice that <html>noun</html> isn't wrapped in inverted commas because <html>noun</html> isn't text itself. It is the name of a variable that represents text.
   * Run the code as is to check that it replaces 'ball' properly.   * Run the code as is to check that it replaces 'ball' properly.
-  * Not every word we want to replace has its own tag, so lets add <html><span></html> for <html>Sam</html>, <html>tummy</html> and <html>smelling</html>.+  * Not every word we want to replace has its own tag, so lets add <html><span></html> for <html>dog</html>, <html>Sam</html>, <html>tummy</html> and <html>smelling</html>.
 <code><p style="text-align:right"> <code><p style="text-align:right">
-My friend Pablo has a <em style="color:red; font-weight:700">pet dog</em> called <span>Sam</span> who likes to have his <span>tummy</span> scratched. When they go to the park, <strong>he likes to chase a <em>ball</em>.</strong> He rolls in the dirt so Pablo has to wash him when they get home.+My friend Pablo has a <em style="color:red; font-weight:700">pet <span>dog</span></em> called <span>Sam</span> who likes to have his <span>tummy</span> scratched. When they go to the park, <strong>he likes to chase a <em>ball</em>.</strong> He rolls in the dirt so Pablo has to wash him when they get home.
 </p> </p>
 <p style="text-indent:50px"> <p style="text-indent:50px">
en/web_development/text/javascript.1644443075.txt.gz · Last modified: 2023/08/16 09:33 (external edit)