This is what I have that works:
function content() {
var dd = document.getElementById("stuff1")
dd.classList.toggle('disp');
}
<li onclick="content()"></li>
This is what I want to do:
function content(x) {
var dd = document.getElementById("x")
dd.classList.toggle('disp');
}
<li onclick="content(stuff1)"></li>
But that doesn't work. What is the proper way to accomplish this?
Both other answers correctly state you need to remove the quotes from your getElementById
call so that:
var dd = document.getElementById(x);
But you also need to add quotes to your content
call in the onclick
handler body:
<li onclick="content( 'stuff1' )"></li>
Otherwise the stuff1
is treated as a variable name and not a string.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句