I’ve searched high and low for the answer to my question. I have the code below, and simply would like to have my JQuery function to hide a specific row returned by the foreach loop. Currently it hides all rows returned. I’m using JQuery in .cshtml. Please advise.
<body>
<script type="text/javascript">
$(document).ready(function(){
$("input").click(function(){
$("p").toggle(1000);
});
});
</script>
@foreach (var row in db.Query(selectQueryString)){
<p>First Name: @row.First_Name Last Name:@row.Last_Name</p>
<button>Toggle</button>
}
</body>
This should work for you:
Live DEMO
Edit:
When you use
$("p")as a selector in jquery you are actually getting all<p>tags; however, in your case you only wanted the one prior to each button. Therefore, you should the prev() which gets the first instance of the<p>prior to the clicked button.