英文:
Pickles Exercise - change the text by using DOM
问题
// YOUR CODE GOES IN HERE:
const spanElement = document.querySelector('span');
spanElement.textContent = 'Disgusting';
请尝试使用上述JavaScript代码来更改<span>元素中的文本。
英文:
<!DOCTYPE html>
<head>
<title>Pickles</title>
<!--LEAVE THESE LINES ALONE, PLEASE! THEY MAKE THE LIVE PREVIEW WORK!-->
<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>
<!--PLEASE LEAVE THIS LINE ALONE! MAKE YOUR CHANGES USING JAVASCRIPT!!-->
<h1>Pickles Are <span>Delicious</span></h1>
</body>
</html>
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('span').textContent = 'Disgusting';
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("span");
PickleTaste[0].textContent = "Disgusting";
console.log(PickleTaste);
<!-- language: lang-html -->
<!DOCTYPE html>
<html>
<head>
<title>Pickles</title>
<!--LEAVE THESE LINES ALONE, PLEASE! THEY MAKE THE LIVE PREVIEW WORK!-->
<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>
<!--PLEASE LEAVE THIS LINE ALONE! MAKE YOUR CHANGES USING JAVASCRIPT!!-->
<h1>Pickles Are <span>Delicious</span></h1>
</body>
</html>
<!-- end snippet -->
Can't do much to prove I didn't copy Anil kumar
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论