K
K
kmisha2018-02-19 16:47:00
JavaScript
kmisha, 2018-02-19 16:47:00

How to do 2 actions on a button?

Tell me how, when you click on the button, to download the file and open a popup on the site.
The download button itself:

<div class="btn" onclick="location.href='file.xlsx';">Скачать</div>

My windows are called like this:
<div class="btn-b" data-fancybox data-animation-duration="700" data-src="#Modal" href="javascript:;">Открыть</div>

How to combine them?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
aloky, 2018-02-19
@aloky

document.querySelector('.btn-b').addEventListener("click", function(){location.href='file.xlsx'})

And why are you creating a button div=(
<div class="btn-b" data-fancybox data-animation-duration="700" data-src="#Modal" href="javascript:;">Открыть</div>
<script>
document.querySelector('.btn-b').addEventListener("click", function(){location.href='file.xlsx'})
</script>

A
Astrohas, 2018-02-19
@Astrohas

document.querySelector('.btn-c').addEventListener("click", function(){location.href='file.xlsx'})

S
Subb98, 2018-02-19
@Subb98

Make one button, instead of two, and place your own handler in onclick, in which the functions you need will be called. Example: https://codepen.io/Subb98/pen/qxxKLb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question