Before you mark this duplicate again, you should know that I have been struggling with this for hours. I have tried just about every method I can find on this site (including the one it is a "duplicate" of), but nothing is working.
I have a button (#form-toggle
) that I want to add display: block;
to a hidden div at the bottom of the page.
I see this error in Chrome's console: Uncaught TypeError: Cannot read property 'click' of null
but have no idea what it means.
This is a simplified version of the elements I want to interact with each other:
HTML
<a id="form-toggle" href="#form-row">Click Me</a>
[web page]
<div id="form-row">
<div class="[several other classes] marketo-form"></div>
</div>
JS
$(document).ready(function(){
var button = document.getElementById('form-toggle');
button.onclick = function() {
var div = document.getElementsByClassName('marketo-form');
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
}
};
});
This is just one of about 10 different scripts I've found on here and tried. I am a front end guy [designer], I have no idea what I'm doing with this stuff. There is a second button at the bottom of the page, which works fine to accomplish this. I didn't write the script, so I don't know how to edit it. It's below, if that might help troubleshooting.
HTML
<div id="form-row">
<div class="get-in-touch-2 mkto1866mkto" >
<a href="#">Schedule a Demo</a>
</div>
<div class="marketo-form">
<form id="mktoForm_1866"></form>
</div>
</div>
JS
$('.get-in-touch-2').on('click', function(event){
event.preventDefault();
if ($(this).is('.copy-button')) {
var butClass = $(this).attr('class');
var mktoFormId = butClass.split("mkto");
mktoFormId = mktoFormId[1];
$('#mktoForm_' + mktoFormId).appendTo($(this).parent().find('.marketo-form'));
}
$('.get-in-touch-2').not(this).parent().find('.marketo-form').slideUp();
$('.marketo-comp-block').find('.marketo-form').slideUp();
$(this).parent().find('.marketo-form').slideToggle();
checkWidth();
});