Having some trouble selecting class names with plain \'ol vanilla javascript:
var email = document.getElementsByClassName(\'email\');
var phone = document.getEle
getElementsByClassName
is not defined so your email
and phone
variables are undefined. phone
and email
are loaded then email
and phone
will be undefined. getElementsByClassName
return a node list so you should actually define email
and phone
.Code:
var email = document.getElementsByClassName('email')[0];
var phone = document.getElementsByClassName('phone')[0];
Update: Or loop through the array:
for(var i = 0; i < phone.length; i++)
{
phone[i].style.display = "none";
}