Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

jQuery help? Multiple != attribute...

  • 27-07-2010 05:37AM
    #1
    Closed Accounts Posts: 27,856 ✭✭✭✭


    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,856 ✭✭✭✭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,856 ✭✭✭✭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