ページの上部にスライドするアラートを設定しています。コードでは、href属性はWebアドレスを追加していないようです。私は自分のコンソールに何のエラーも出ていませんが、これを引き起こしているものを見つけることはできません。テストに設定した「Go to Google」ボタンをクリックすると、Googleにつながるはずですが、そうではありませんか?コードとCodepenは以下のとおりですが、どんな助けも素晴らしいでしょう。追加href属性が機能していません - Javascript
Codepenはここにある:https://codepen.io/emilychews/pen/ZyGrrR
HTML
<div id="header">Original Header</div>
CSS
* {font-family: arial;
line-height: 100px;}
#header {width: 100%;
height: 100px;
background: red;
color: white;
text-align: center;}
div#newBar {
width: 100%;
height: 50px;
background-color: blue;
line-height: 50px;
text-align: center;
color: white;
}
div#topbar_button {
display: flex;
justify-content: center;
align-items: center;
width: 11%;
height: 54%;
background: white;
position: relative;
bottom: 41PX;
margin-left: 75%;
color: blue;
border-radius: 2px;
}
JAVASCRIPT
// window.onload = function() {
var header = document.getElementById('header');
var newBar = document.createElement('div');
newBar.id = "newBar";
var newBarText = document.createTextNode("Click on the link to go to Google");
newBar.appendChild(newBarText);
// create button and anchor tag and append
var topBarButton = document.createElement('div');
topBarButton.id = "topbar_button";
var anchorTag = document.createElement('a');
anchorTag.setAttribute('href', 'www.google.co.uk');
topBarButton.appendChild(anchorTag);
topBarButton.innerHTML = "Visit Google";
newBar.appendChild(topBarButton);
// append new top bar to header
var header = document.getElementById('header');
header.parentNode.insertBefore(newBar, header);
// };
anchorTag.innerHTML = "Googleにアクセス"する必要があります。 –