How could I get all values of labels that contains class "timeAuction"?
I am writing JavaScript function that will get each label with class name
timeAuction
<label id="@Html.Raw("time" + item.IDAuc)" class="displayLabelProduct timeAuction">
@diff.ToString(@"dd\:hh\:mm\:ss")
</label>
You can select all elements using the class selector:
var allElements = $(".timeAuction");
You can also use $.each
to iterate the collection.
$(".timeAuction").each(function() {
$(this).text("Random value");
});
Full snippet showing modification of labels:
$(".timeAuction").each(function(counter) {
$(this).text("New Label " + counter);
});
label {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<label class="displayLabelProduct timeAuction">
Label 1
</label>
<label class="displayLabelProduct timeAuction">
Label 2
</label>
<label class="displayLabelProduct timeAuction">
Label 3
</label>
<label class="displayLabelProduct timeAuction">
Label 4
</label>