How can I trigger a button in HTML using the javascript?
I tried to use the <script></script> the HTML file and it works perfectly fine, but then I want to use a javascript file to trigger when clicking a button in HTML.
here is the code:
JAVASCRIPT in HTML <head></head> tag:
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js">
<script src="jsFiles/index.js"></script>
HTML:
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Message</a>
<a class="dropdown-item" href="#">Settings</a>
<a class="dropdown-item" id="a_id">Log Out</a>
</div>
JAVASCRIPT FILE:
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
$(document).ready(function(){
$("#a_id").click(function(){
swal({title:'Logout',
text:'Do you want to logout this Account?',
icon:'warning',
buttons: true,
dangerMode: true
})
.then((willOUT) => {
if (willOUT) {
window.location.href = 'page-logout.php', {
icon: 'success',
}
}
});
});
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>in your html right above your<script src="jsFiles/index.js"></script>and try it then. jQuery wouldn't work if you don't include it, which is what Obsidian Age is saying