Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I hope your 2015 it's being awesome and thank you from beforehand for taking a minute of your time to help me, first of all, I'm a noob who's been learning by my own...so bear with me if my programming logic it's not up to your expectations or if i'm confusing concepts and of course feel free to correct me, thanks!


how can I target the elements that match such condition?

I've got the next code:

if($(".class").is(':visible') && !$(".class").hasClass('match_group')){
/// target those elements with that specific condition, the goal I wanna reach implies doing things like for example:

$(".class").is(':visible').css({'background-color':'blue'}):

or even better attatch a event handler if posssible
}
Posted
Updated 17-Feb-15 7:03am
v2
Comments
Afzaal Ahmad Zeeshan 17-Feb-15 13:13pm    
Ok, but what is the problem that you're facing?
edward-l 17-Feb-15 14:21pm    
I've got an Input fiel that works as a filter to seek a category once enter is pressed to help users post better, don't worry about that part 'cuz I sorted it out but I'm trying to speficy that when the input field is empty and enter is pressed thoose fields that are "vissible" and don't have the 'match group' class restore their default
Sergey Alexandrovich Kryukov 17-Feb-15 16:19pm    
Your whole approach is wrong, as you are not reusing wrappers obtained via the selectors. You are not dealing with the possibility of having a set of matching elements with not exactly one element. You really need to explain your goal properly to get an advice.
—SA

1 solution

This one-line jquery statement should do the trick:
$(".class:visible:not('.match_group')").css("background-color", "blue");

Try this:
XML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".class:visible:not('.match_group')").css("background-color", "blue");
});
</script>
</head>
<body>
<p class="class">visible has class but no match_group</p>
<p class="class match_group">visible has class and match_group</p>
<p class="class" style="display: none">not visible has class but no match_group</p>
<p class="class match_group" style="display: none">not visible has class and  match_group</p>
</body>
</html>
 
Share this answer
 
Comments
edward-l 18-Feb-15 9:08am    
Peter if I could I'd hug you and buy you beer, thank you so much for your time:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900