Pickles Exercise – 使用DOM更改文本

huangapple go评论71阅读模式
英文:

Pickles Exercise - change the text by using DOM

问题

// YOUR CODE GOES IN HERE:
const spanElement = document.querySelector('span');
spanElement.textContent = 'Disgusting';

请尝试使用上述JavaScript代码来更改<span>元素中的文本。

英文:
&lt;!DOCTYPE html&gt;

&lt;head&gt;
    &lt;title&gt;Pickles&lt;/title&gt;
    &lt;!--LEAVE THESE LINES ALONE, PLEASE! THEY MAKE THE LIVE PREVIEW WORK!--&gt;
    &lt;script src=&quot;node_modules/babel-polyfill/dist/polyfill.js&quot; type=&quot;text/javascript&quot;&gt; &lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
    &lt;!--PLEASE LEAVE THIS LINE ALONE! MAKE YOUR CHANGES USING JAVASCRIPT!!--&gt;
    &lt;h1&gt;Pickles Are &lt;span&gt;Delicious&lt;/span&gt;&lt;/h1&gt;
&lt;/body&gt;

&lt;/html&gt;

Select the <span> element that currently reads "Delicious".

Change its text to read "Disgusting" USING JAVASCRIPT.

// YOUR CODE GOES IN HERE:
const pickleTaste = document.getElementsByTagName(&#39;span&#39;).textContent = &#39;Disgusting&#39;;
console.log(pickleTaste);

I tried with innerText, textContent and innerHTML, However solution doesn't pass.

答案1

得分: 1

以下是代码的翻译部分:

// document.getElementsByTagName() 返回一个数组,而不是一个单一的节点
var PickleTaste = document.getElementsByTagName("span");
PickleTaste[0].textContent = "恶心";
console.log(PickleTaste);
<!DOCTYPE html>
<html>
  <head>
      <title>泡菜</title>
      <!-- 请不要改动以下这些行,它们让实时预览工作正常! -->
      <script src="node_modules/babel-polyfill/dist/polyfill.js" type="text/javascript"> </script>
      <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  </head>
  <body>
      <!-- 请不要改动以下这行,使用JavaScript进行更改! -->
      <h1>泡菜是 <span>美味的</span></h1>
  </body>
</html>
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

// document.getElementsByTagName() returns an array, not a singular node
var PickleTaste = document.getElementsByTagName(&quot;span&quot;);
PickleTaste[0].textContent = &quot;Disgusting&quot;;
console.log(PickleTaste);

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Pickles&lt;/title&gt;
      &lt;!--LEAVE THESE LINES ALONE, PLEASE! THEY MAKE THE LIVE PREVIEW WORK!--&gt;
      &lt;script src=&quot;node_modules/babel-polyfill/dist/polyfill.js&quot; type=&quot;text/javascript&quot;&gt; &lt;/script&gt;
      &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!--PLEASE LEAVE THIS LINE ALONE! MAKE YOUR CHANGES USING JAVASCRIPT!!--&gt;
      &lt;h1&gt;Pickles Are &lt;span&gt;Delicious&lt;/span&gt;&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

Can't do much to prove I didn't copy Anil kumar

huangapple
  • 本文由 发表于 2023年2月27日 14:32:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定