I want to toggle the first div after the input
Is it possible?
Ive tryed
<script type="text/javascript">
function spoiler() {
$(this).next().show();
}
</script>
<div>
<input value="Show/Hide" style="" onclick="spoiler();" type="button"/>
</div>
<div style="display:none;">
Text
</div>
I can’t use classes or ids
Your code wasn’t working because
$(this)wasn’t referencing your button. Also,.next()looked for the element after the button, which doesn’t exist. You’re looking for the element after the parent of that button.Also, instead of binding the event using
onclick, just bind it entirely with JavaScript:You can then simplify your HTML:
Demo: http://jsfiddle.net/NXM7w/