html - what's the difference between $('.p') and $('p') jquery? -


i'm new jquery, when select class html, can $('.p') or $('p'). i'm confused, there difference?

these css selectors. can used in jquery is.

  1. $('.p') class selector. select elements having class p.

    in html document, css class selectors match element based on contents of element's class attribute. class attribute defined space-separated list of items, , 1 of items must match class name given in selector.

example:

<a class="p">...</a> <div class="p anotherclass">...</div> <span class="firstclass p">...</span> <p class="p">...</p> 
  1. $('p') element/tag/type selector. select p(paragraph) elements.

    css type selectors match elements node name. used alone, therefore, type selector particular node name selects elements of type — is, node name — in document.

example:

<p>...</p> <p class="anyclass">...</p> <p id="anyid">...</p> 
  1. also, there id selector. $('#p') select element having id of p.

    in html document, css id selectors match element based on contents of element's id attribute, must match value given in selector.

example:

<anyel id="p">...</anyel> 

mdn selectors doc


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -