0

I have the following function

function show(x) {
document.querySelector(x).classList.toggle('hide');}

I am using it on html

<button onclick="show('p')">Button 1</button>
<p>This is p</p>
<button onclick="show('div')">Button 2</button>
<div>This is div</div>

Hide by default

window.onload = show('p');

Now I want to get all show() arguments so that window onload dinamicly change whatever the queryselector is.

  • Inline event handlers like `onclick` are [not recommended](/q/11737873/4642212). They are an [obsolete, hard-to-maintain and unintuitive](/a/43459991/4642212) way of registering events. Always [use `addEventListener`](//developer.mozilla.org/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_%E2%80%94_dont_use_these) instead. The (also discouraged) `onclick` property requires a _function_. `show("p")` is _not a function_. – Sebastian Simon Dec 07 '21 at 14:04

0 Answers0