jQuery: filter out elements via class?

后端 未结 3 621
无人共我
无人共我 2020-12-29 06:53

I have a website featuring a long list of names. To make it more oversee-able, I\'d like to put a text link in to

(on load) show all

(on clicking word \"pea

3条回答
  •  醉话见心
    2020-12-29 07:02

    hmm.. if you had a list like the following:

    red apple
    green apple
    big pear
    little pear
    

    the following would show all:

    $("span.*").show();
    

    the following would hide all elements with 'class="apple"':

    $("span[class='apple']").hide();
    

    or you could go with hiding everything that doesn't have 'class="pear"':

    $("span[class!='pear']").hide();
    

提交回复
热议问题