troubleshooting Question

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

Avatar of ShanghaiD
ShanghaiDFlag for United Kingdom of Great Britain and Northern Ireland asked on
jQuery
3 Comments2 Solutions421 ViewsLast Modified:
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');
ASKER CERTIFIED SOLUTION
Jon Norman
Information Systems Manager
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros