Thanks mgebhard, but this will loop through the entire set with an if condition for the .data- value. I was hoping for applying the filter directly in the .each loop
for example it should be able to do some kind of a where clause similar to razor:
Thanks mgebhard, but this will loop through the entire set with an if condition for the .data- value. I was hoping for applying the filter directly in the .each loop
for example it should be able to do some kind of a where clause similar to razor:
$(".myDiv").Where(r => r.item == 2).each(function (index, value) {
Or there must be something similar hopefully?
Thanks again.
It looks like you're mixing Linq (server) with JavaScript (client). Or maybe you're using a JavaScript library that you forgot to mention?
Anyway, I also showed how to do this using a simple selector which takes one line of code.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Fei, thanks, this did work except for one thing - if you set the data-item field within the same event (click), persistance is not recognized - it uses the original data-item value, rather than the new one.
Fei, thanks, this did work except for one thing - if you set the data-item field within the same event (click), persistance is not recognized - it uses the original data-item value, rather than the new one.
Member
246 Points
471 Posts
how to add filter to jquery .each
Jul 25, 2016 06:12 PM|gunderj|LINK
For the loop below...
$(".myDiv").each(function () {
alret("id: " + this.id);
});
Is there a way to add a filter that will loop through myDiv for a certain data- value?
Thanks
All-Star
52241 Points
23313 Posts
Re: how to add filter to jquery .each
Jul 25, 2016 06:31 PM|mgebhard|LINK
The following shows how to do this with an $.each() and a selector.
Member
246 Points
471 Posts
Re: how to add filter to jquery .each
Jul 25, 2016 06:43 PM|gunderj|LINK
Thanks mgebhard, but this will loop through the entire set with an if condition for the .data- value. I was hoping for applying the filter directly in the .each loop
for example it should be able to do some kind of a where clause similar to razor:
All-Star
52241 Points
23313 Posts
Re: how to add filter to jquery .each
Jul 25, 2016 07:14 PM|mgebhard|LINK
It looks like you're mixing Linq (server) with JavaScript (client). Or maybe you're using a JavaScript library that you forgot to mention?
Anyway, I also showed how to do this using a simple selector which takes one line of code.
All-Star
40535 Points
6233 Posts
Microsoft
Re: how to add filter to jquery .each
Jul 26, 2016 02:23 AM|Fei Han - MSFT|LINK
Hi gunderj,
You could try to use jQuery Attribute Equals Selector to filter the elements before you call .each() method to loop through the matched elements.
Best Regards,
Fei Han
Member
246 Points
471 Posts
Re: how to add filter to jquery .each
Jul 26, 2016 03:14 PM|gunderj|LINK
Fei, thanks, this did work except for one thing - if you set the data-item field within the same event (click), persistance is not recognized - it uses the original data-item value, rather than the new one.
All-Star
52241 Points
23313 Posts
Re: how to add filter to jquery .each
Jul 26, 2016 07:31 PM|mgebhard|LINK
Show your code.