JQuery Attribute Manipulation

When I browse the web for information about jQuery and I got a jquery cheat sheet. There I am very confused about how to use the following condition. Help me.

[attribute|=val]
[attribute*=val]
[attribute~=val]
[attribute$=val]
[attribute=val]
[attribute!=val]
[attribute^=val]
[attribute]
[attribute1=val1] [attribute2=val2]

      

What are the functions of these special characters *, ~, $,!, ^? Many thanks.

+2


a source to share


1 answer


Refer to attribute selectors :

  • =

    : equals
  • ^

    : starts with
  • $

    : ends with
  • !

    : not equal
  • *

    : contains
  • ~

    : contains word
  • |

    : contains a prefix
  • [name]

    : has an attribute name

Your last example can mean one of two things depending on whether it has a gap in between or not:



  • [attr1=foo][attr2=bar]

    means to find elements that have an attribute attr1

    with a value foo

    and attr2

    with a value bar

    ; but

  • [attr1=foo] [attr2=bar]

    means to find elements attr1

    with a value attribute foo

    that have descendants attr2

    with a value attribute bar

    .

Space here makes an important semantic difference in expression.

+5


a source







All Articles