My javascript code won't execute, even tough my console doesn't give any errors [duplicate]

问题: This question already has an answer here: What do querySelectorAll and getElementsBy* methods return? 9 answers I'm trying to show a map when I cli...

问题:

This question already has an answer here:

I'm trying to show a map when I click on an h1 element. So I wrote my code which should do the trick but nothing happens. So I went looking for my JS console in my browser and there weren't any errors so I'm kinda stuck right now. Anyone that can help me out?

my HTML:
<section class="WT1">
<h1>Wetenschap & Techniek - Ellermanstraat &#8595</h1>
<div id="mapid"></div>
</section>


my JS
var touchMe = document.getElementsByTagName('h1');

touchMe.onhover = function() {
touchMe.style.cursor = 'pointer';
}

touchMe.onclick = function() {
document.getElementById('mapid').style.display = "block";
};

回答1:

getElementsByTagName returns an array of elements, select one item from it

var touchMe = document.getElementsByTagName('h1')[0]
  • 发表于 2019-03-13 17:40
  • 阅读 ( 171 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除