Why doesn't this jquery selector with a period work

后端 未结 9 1991
长发绾君心
长发绾君心 2020-12-06 04:56

I have a div with an ID

this jquery selector works

$(\"[id^=\'updates-pane         


        
相关标签:
9条回答
  • 2020-12-06 05:34

    Yes, HTML5 allows period in id but jQuery isn't built by the w3 org. It's just a utility library optimized for the most common cases.

    If your ID has a period, or any other character making jQuery parse it as more than just an id, then you'd better use the standard function :

    $(document.getElementById(yourId))
    

    This is the preferred solution if your id comes from a variable.

    0 讨论(0)
  • 2020-12-06 05:35

    Use this to escape your dot:

    $("#updates-pane-user\\.followed_on")
    

    Reference: http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_element_by_an_ID_that_has_characters_used_in_CSS_notation.3F

    0 讨论(0)
  • 2020-12-06 05:41

    Because of the dot in the id attribute which in jQuery syntax represents class selector. This selector is equivalent to selecting node as:

    <div id="updates-pane-user" class="followed_on">

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