I have a piece of code here that is repeated multiple times in a single html file.
<div class="message">
<label id="slideDown"> Read </label>
<p id="messageBody" class="hidden"> Body </p>
</div>
<div class="message">
<label id="slideDown"> Read </label>
<p id="messageBody" class="hidden"> Body </p>
</div>
jQuery used to slide down messageBody.
$('#slideDown').click(function() {
$('#messageBody').slideToggle('slow');
});
My questions is how can I get it so that when I click on the label Read for one message, it only slides down the messageBody that is within its div?
You are using the ids
slideDownandmessageBodymultiple times, while ids have to be unique. What happens when you use ids more than once doesn’t have to make any sense at all, as your document is just malformed.Anyway, the way to fix this would be change the ids to be unique. One way would be like this:
js: