html - How can I change a button Id-tag into class-tag and use getElementByClassName right? -
i need button id several buttons thats why want change class-tag. if not work. not possible use elementbyclassname ?
<button class="mybtn">overlay</button>
so want change id-tag class-tag. tried change getelementbyid getelementbyclassname. unfortunatly not work.
in following have added example w3schools. working id-tag.
<!doctype html> <html> <head> <style> /* overlay (background) */ .overlay { display: none; /* hidden default */ position: fixed; /* stay in place */ z-index: 1; /* sit on top */ left: 0; top: 0; width: 100%; /* full width */ height: 100%; /* full height */ overflow: auto; /* enable scroll if needed */ background-color: rgb(0,0,0); /* fallback color */ background-color: rgba(0,0,0,0.4); /* black w/ opacity */ -webkit-animation-name: fadein; /* fade in background */ -webkit-animation-duration: 0.4s; animation-name: fadein; animation-duration: 0.4s } /* overlay content */ .overlay-content { position: fixed; bottom: 0; background-color: #fefefe; width: 100%; -webkit-animation-name: slidein; -webkit-animation-duration: 0.4s; animation-name: slidein; animation-duration: 0.4s } /* close button */ .close { color: white; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: #000; text-decoration: none; cursor: pointer; } .overlay-header { padding: 2px 16px; background-color: #5cb85c; color: white; } .overlay-body {padding: 2px 16px;} .overlay-footer { padding: 2px 16px; background-color: #5cb85c; color: white; } /* add animation */ @-webkit-keyframes slidein { {bottom: -300px; opacity: 0} {bottom: 0; opacity: 1} } @keyframes slidein { {bottom: -300px; opacity: 0} {bottom: 0; opacity: 1} } @-webkit-keyframes fadein { {opacity: 0} {opacity: 1} } @keyframes fadein { {opacity: 0} {opacity: 1} } </style> </head> <body> <h2>overlay</h2> <!-- trigger/open overlay --> <button id="mybtn">overlay</button> <!-- overlay --> <div id="overlay" class="overlay"> <!-- overlay content --> <div class="overlay-content"> <div class="overlay-header"> <span class="close">×</span> <h2>container</h2> </div> <div class="overlay-body"> <p>container information</p> <p>some other text...</p> </div> <div class="overlay-footer"> <h3>footer</h3> </div> </div> </div> <script> // overlay var overlay = document.getelementbyid('overlay'); // button opens overlay var btn = document.getelementbyid("mybtn"); // <span> element closes overlay var span = document.getelementsbyclassname("close")[0]; // when user clicks button, open overlay btn.onclick = function() { overlay.style.display = "block"; } // when user clicks on <span> (x), close overlay span.onclick = function() { overlay.style.display = "none"; } // when user clicks anywhere outside of overlay, close window.onclick = function(event) { if (event.target == overlay) { overlay.style.display = "none"; } } </script> </body> </html>
you looking getelementsbyclassname. getelementbyclassname not exist.
wiki
Comments
Post a Comment