I got a list of multiple elements like you can find in the example snippet below and I'd like to get all elements with a specific attribute ("test"=true)
.
$(function() {
let elements = $(".myClass") // This property can no be changed so all I got is a variable that includes the callback of multiple jQuery elements.
// How to extract all elements with the "test"-attribute from the elements property without using a each function?
console.log(elements)
$(elements).each(function() {
console.log($(this).attr("test") === "true")
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="myClass">A</div>
<div class="myClass">B</div>
<div class="myClass" test=true>C</div>
Is there any method
that extracts just elements with specific properties like an attribute named test? Any help would be really appreciated.