Avatar of ShanghaiD
ShanghaiD
Flag for United Kingdom of Great Britain and Northern Ireland asked on

jquery -- Can anyone improve my syntax to combine selectors?

I have code which works, but I am trying to improve it (and learn more about jQuery)!

My current code selects images inside a <td> column in a table, where some <img> have class='add' and some have class='view'.

For the class='add' it then filters depending on the text value in the previous <td> column.

For the class='add' it discards -- using not() -- based on an internal function -- daysBetween() -- being applied to a data item attached to the row.

Both of these separately filtered selections then have the same class applied to them (to change the background colour of the column) and the same effect on the <img>. -- to make it pulsate.

My current code is as follows:

     $('.add').filter(function() {return parseInt($(this).parent().prev().text())>120}).effect('pulsate', 'slow').parent().addClass('bgRed');

      $('.view').not(function() {return daysBetween($(this).parent().parent().data('lastedit'))<15}).effect('pulsate', 'slow').parent().addClass('bgRed');

My question is, how can the two selector criteria be combined, so the addClass() and effect() can then be applied once to everything?  

In other words, how do I combine
$('.add').filter(function() {return parseInt($(this).parent().prev().text())>120})
with
$('.view').not(function() {return daysBetween($(this).parent().parent().data('lastedit'))<15})
and then apply
.effect('pulsate', 'slow').parent().addClass('bgRed');
jQuery

Avatar of undefined
Last Comment
ShanghaiD

8/22/2022 - Mon
SOLUTION
stergium

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Jon Norman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ShanghaiD

ASKER
Thank you (both) for pointing me in the right direction (and expanding my jQuery knowledge).  I've awarded most points to stergium for his quick response but I also appreciated the fine-tuning from JonNorman.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes