Solution: my output div had a z-index of -1, so it was making the buttons unclickable. thank you j08691 in the comments
I have a series of buttons that are created in JS to perform a function onclick. If I write the button on the page itself, it works fine. But when they're created within JS and written to the document with .innerHTML, they don't function at all. Is there something about buttons that they won't work when created this way, after the page is loaded? Will I need to add the event listener manually?
As a note, I'm not running this on a server, so everything has to run client-side.
<button class="tag" onclick="alert('Button Clicked!')">Text</button>
The HTML is identical. I ran the function, then literally copied the element from the page source and pasted it into the body directly to test it and it works fine there.
Edit for reprex
body {
width: 7in;
margin-left:auto;
margin-right:auto;
}
#patterns-output {
position: relative;
z-index: -1;
}
#search-bar {
display: none;
position: fixed;
top: 0px;
width: 7in;
padding: 0.140in;
margin-bottom: 0.125in;
background: white;
border-bottom: solid 1px black;
}
#loading-icon {
margin: auto;
display: none;
}
.pattern {
width: 7in;
margin-left:auto;
margin-right:auto;
border: 1px solid black;
border-radius: 5px;
padding: 0.125in;
margin-bottom: 0.125in;
}
.info {
width: inherit;
border: 0px solid green;
}
.pattern-image {
width: 3in;
float: right;
border: 0px solid blue;
}
.thread-image-container {
width: 20px;
height: 20px;
position: relative;
left: -5px;
top: 3px;
float: left;
overflow: hidden;
border: 0px solid blue;
}
.thread-image {
position: relative;
left: -600px;
top: -619px;
}
.tag {
float: left;
margin-bottom: 5px;
margin-right: 5px;
}
.thread-changes {
width: inherit;
clear: both;
border: 0px solid yellow;
}
.cols {
/* 7in wide - (0.3" padding x2) = 6.4" - 0.4 gap = 6" / 2 = 3" col */
column-count: 2;
column-gap: 0.4in;
column-width: 3in;
border: 0px solid purple;
}
ul, ol {
padding-left: 0.3in;
}
<html lang="en">
<head>
<title>Embroidery Database</title>
</head>
<body>
<div id="search-bar" style="display: inline;">
<button class="tag" onclick="alert('Button Clicked')">Test</button>
</div>
<div id="patterns-output" style="top: 59px;">
<div class="pattern" id="M18731">
<img class="pattern-image" src="patterns/M18731.jpg">
<b>A Little Dirt Never Hurt</b> (M18731)<br>
5.5in wide x 4.85in high (17353 stitches)
<ul><b>Thread List</b> (4)
<li><div class="thread-image-container"><img class="thread-image" src="threads/910-1048.jpg"></div>Celery (#1048)</li>
<li><div class="thread-image-container"><img class="thread-image" src="threads/910-1184.jpg"></div>Scarlet Rose (#1184)</li>
<li><div class="thread-image-container"><img class="thread-image" src="threads/910-1058.jpg"></div>Sienna (#1058)</li>
<li><div class="thread-image-container"><img class="thread-image" src="threads/910-1065.jpg"></div>Copper (#1065)</li>
</ul>
<button class="tag" onclick="alert('Button Clicked')">Text</button>
<button class="tag" onclick="alert('Button Clicked')">Plants</button>
<br>
<div class="thread-changes">
<ol><b>Thread Changes</b> (4)
<div class="cols">
<li>Celery: Vegetable Tops, Text</li>
<li>Scarlet Rose: Radish, Beet, Text</li>
<li>Sienna: Text</li>
<li>Copper: Carrot</li>
</div>
</ol>
</div>
</div>
</div>
</body>
</html>