Im trying to alert the current value that is in the input box depending on which button you click on. So if the first grid-2 button is selected it would alert 1 and if the second button with the input value of 2 was to be clicked on instead it would alert that number etc.
<div class='grid-2'>
<input class="photo1" value="1">
<a class='remove-photo' href='#'>Remove Now</a>
</div>
<div class='grid-2'>
<input class="photo1" value="2">
<a class='remove-photo' href='#'>Remove Now</a>
</div>
<div class='grid-2'>
<input class="photo1" value="3">
<a class='remove-photo' href='#'>Remove Now</a>
</div>
<div class='grid-2'>
<input class="photo1" value="4">
<a class='remove-photo' href='#'>Remove Now</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".remove-photo").click(function() {
var current_selected_photo_num = $(".photo1").val();
alert(current_selected_photo_num);
});
});
</script>
Use the .prev() function to go upwards through siblings
$(".remove-photo").click(function() {
var current_selected_photo_num =
$(this).prev('.photo1').val();
alert(current_selected_photo_num);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With