jQuery what is the difference between $('

') and $('p')

后端 未结 3 516
野的像风
野的像风 2021-01-23 09:46

Can someone explain to me the difference between $(\'

\') and $(\'p\') in jQuery.

for example, if i write:

$(\'body\').         


        
3条回答
  •  伪装坚强ぢ
    2021-01-23 10:09

    jQuery can parse HTML an create an actual DOM element. That is, when you do something like $("

    "), jQuery is parsing the markup and internally creating a DOM paragraph element that can be appended to the document.

    In the other hand, jQuery integrates Sizzle, a CSS selector engine. The jQuery function accepts CSS selectors, meaning that $("p") is selecting all paragraph elements in the document. You can also use more complex selectors like $("p:first-child") and select the first paragraph of the document.

    Learn more about jQuery CSS selectors here.

提交回复
热议问题