Link to home
Start Free TrialLog in
Avatar of ShanghaiD
ShanghaiDFlag 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');
SOLUTION
Avatar of stergium
stergium
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.