前提・実現したいこと
よくある名前を入力すると診断できるというツールを練習で作ってて、診断ボタンをクリックすると反応したか確認のためコンソールに押されましたと表示させようとしたらエラーがでました。
発生している問題・エラーメッセージ
Uncaught TypeError: Cannot set property 'onclick' of null
at 診断.js:7
該当のソースコード
Java
(function () {
'use strict';
const userNameInput = document.getElementById('user-name');
const assessmentButton = document.getElementById('assessment');
const resultDivided = document.getElementById('result-area');
const tweetDivided = document.getElementById('tweet-area');
assessmentButton.onclick = ()=> {
console.log('ボタンが押されました');
};
HTML
<body> <script src="診断.js"></script> <h1>あなたのいいところは?</h1> <p>診断したい名前を入れてください</p> <input type='text' id='user-name' size='40' maxlength="20"> <button id='assesment'>診断する</button> <div Id='result-area'></div> <div id='tweet-area'></div> </body>試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー