Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

jQuery help? Multiple != attribute...

Options
  • 27-07-2010 5:37am
    #1
    Closed Accounts Posts: 27,857 ✭✭✭✭


    Hey folks,

    Kinda confusing thread title :p

    I'm trying to use jQuery to filter search results, removing all elements except for(about 10.

    The search results are of the form:
    <div class="searchresult" fn="search_result_name_1">crap here</div>
    <div class="searchresult" fn="search_result_name_2">crap here</div>
    <div class="searchresult" fn="search_result_name_3">crap here</div>
    <div class="searchresult" fn="search_result_name_4">crap here</div>
    <div class="searchresult" fn="search_result_name_5">crap here</div>
    <div class="searchresult" fn="search_result_name_6">crap here</div>
    etc
    

    The following code will not work :( :
    $(document).ready(function() {
    
    $("div[fn!='search_result_name_1']").css('display', 'none');
    $("div[fn!='search_result_name_2']").css('display', 'none');
    $("div[fn!='search_result_name_3']").css('display', 'none');
    
    });
    

    It just removes everything.

    Any suggestions?

    Obviously something a bit more graceful than what I was attempting above would be appreciated ;)

    Cheers folks,

    Dave


Comments

  • Closed Accounts Posts: 27,857 ✭✭✭✭Dave!


    Where'd everybody go? :p

    Okay I figured that out. This works (for my purposes):
    $("div:not([fn=testFn2],[fn=testFn1])").hide();
    

    However, I soon discovered that it i. hides div's with fn not equal to the specified ones (great), but also, ii. removes div's with no fn attribute :o

    So that's not exactly great! :D

    Now I want to select "all divs with class className, who do not have fn values of value1, value2...valueN"

    Any help? :)


  • Closed Accounts Posts: 27,857 ✭✭✭✭Dave!


    Thanks for the help everyone :D After much ado, this seems to do the job:
    $(document).ready(function() {
    
    $(".testDiv:not([fn='value1'],[fn='value2'],[fn='value3'],[fn='value4'],[fn='value5'],[fn='value6'])").hide();
    
    });
    


Advertisement