jQuery selector question. Select all nodes that do NOT START with (string)

后端 未结 3 794
臣服心动
臣服心动 2021-01-01 11:36

Trying to assemble a rather complex jQuery selector here, and having trouble.

Essentially, I\'m trying to grab all anchors that that 1) do not have a \"rel\" of \"fa

相关标签:
3条回答
  • 2021-01-01 12:08

    Shouldn't it be:

    $("a:not([rel='facebox'],[href^='mailto'])");
    
    0 讨论(0)
  • 2021-01-01 12:16

    You want the :not selector

    $("a:not([rel=facebox],[href^=mailto])");
    

    EDIT: I stole your answer for correctness

    0 讨论(0)
  • 2021-01-01 12:21

    Alright Mr. Jeremy Ricketts. Jquery has messed up your head. You are trying to chain selector logic...kind of like how jQuery chains methods. In your second selector (a[href!^="mailto"]) you are trying to say...NOT things that contain THIS attribute. What you are saying is "Search for all things that are not mailto" and "Search for all things that contain mailto". It's like light filters...if you filter red light...and throw a yellow light filter on top...you are not filtering for orange light...you just filtered out EVERYTHING (sorry for the stretch of an analogy). So what you are trying to do is use the pseudo selector :not.

    Like this - $(a:not([href^=mailto:])).whateverJqueryMethodYouWant();

    EDIT: Well now that you have spec'd out the question properly...you can do it like this - $(a:not([href^=mailto:] , [rel=facebox])).whateverJqueryFunctionYouWant();

    0 讨论(0)
提交回复
热议问题