Trying to work out if it's possible to have multiple toggle buttons on my page while not having to repeat jQuery .toggleClass code for each button (with different id's)? Maybe use 'this' or some other method?
$(document).ready(function(){
$("button").click(function(){
$("p").toggle('fast');
});
});
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<button>Toggle</button>
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
<button>Toggle</button>
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</body>
</html>
Thanks in advance!
to toggle the next p you need to use .next()
to toggle the next p and next next p you need to use .next()
you can select your button ids like
I don't prefer your html structure .. if you can put each button and its P in one div it will be better to handle