You're likely looking for a solution that gets a div containing or adjacent to your button, or a child of an adjacent element. I'd suggest something along these lines:
(Some alternatives notwithstanding depending on your particular use-case. e.g. innerText vs textContent or parentNode vs parentElement, and target vs currentTarget.)
Great! Works fine as far as the saving goes..
Just how can I select the div class I want the button to save? I cannot figure that part out..
I have this on the button:
onclick="download('Test', 'MyTasks.txt', 'text/plain')"
And the 'Test' is the text which will appear in the text file, but how can I make it be instead of "Test" whatever is in my certain div class?
You're likely looking for a solution that gets a
div
containing or adjacent to your button, or a child of an adjacent element. I'd suggest something along these lines:With the JS along these lines:
(Some alternatives notwithstanding depending on your particular use-case. e.g.
innerText
vstextContent
orparentNode
vsparentElement
, andtarget
vscurrentTarget
.)You can get contents with
developer.mozilla.org/en-US/docs/W...