What does the selector syntax mean in $( “
” ).text( message )

前端 未结 6 1643
旧巷少年郎
旧巷少年郎 2021-01-03 15:50

What does the selector

syntax mean in this code? I\'ve seen selectors like div or #someId but I\'m confused what the
6条回答
  •  粉色の甜心
    2021-01-03 16:08

    It means "create a jQuery-wrapped div element on the fly".

    See http://api.jquery.com/jQuery/

    From the above:

    jQuery( html [, ownerDocument] )

    Description: Creates DOM elements on the fly from the provided string of raw HTML.

    Later...

    When the parameter has a single tag, such as $('') or $(''), jQuery creates the element using the native JavaScript createElement() function.

    So basically, it's like doing:

    $(document.createElement("div")).text("blahblah");
    

提交回复
热议问题