Jquery | Basic Selectors-Trickcode

jQuery: Basic selector,Element Based Selection,Multi Element Section,ID Based Selector,Class-Based Selector,* Universal Selector
Share it:

 jQuery: Basic selector



  • Basic Selectors are select an element based on their essential features only.
  • We had done the property of basic selectors and their fundamental features.
  • Here, we proceed with the aspects of Basic selectors and some fine Examples of those selectors.

SelectorsDescriptionExample
ElementA selection is Based on an Element Name.$(“p”).text();
Element1,,ElementNIt select several HTML Elements based on an element Name.$(“p”,”h1”,”div”).text();
IdA selection is based on Unique id Attribute.$(“#p1”).text();
ClassIn this selector manipulate a jquery based on an element's class name.$(“.p1”).text();
*This selector called as universal selector that select an entire element.$(*).text();

jQuery: Element Based Selection

  • This selector helps to manipulate the jquery based on the HTMLDocument Element.


$(document).ready(function () {
    $('button').click(function () {
        alert( $('p').text());
    });
});



  • Here,’button’ and ‘p’ are an element based selectors. And click is an event to perform an alert task. 
  • This example shows the P element text when the button fires the click event.


jQuery: Multi Element Section




  • This selector gives an option to select more HTMLElement.
  • It helps to manipulate the jquery based on more than one Element.
  • In this multiple element selection, each and every element separated by a comma,


$(document).ready(function () {
  $('button').click(function () {
        alert($('p,h1,div').text());
    });
});


  • This example shows the text of P,h1, Div elements.

jQuery: ID Based Selector


  • In this selection based on the unique Id of a selected Element.
  • In this selector used to pick a particular or unique element.
  • We mention an Id name followed by # symbol only.

$(document).ready(function () {
    $('#btnclick').click(function () {
        alert($('#p1').text());
    });
});

jQuery: Class-Based Selector


  • This selection based on their class name. The class selectors are followed by.[dot] symbol.
  • It picks an element based on HTMLElement’s class name.


 $(document).ready(function () {
    $('.btn').click(function () {
        alert($('.Ptxt').text());
    });
});

jQuery: * Universal Selector


  • It selects the entire element of the selected element. 
  • The symbol * specifies the entire HTML element.

$(document).ready(function () {
    $('button').click(function () {
        alert($('*').text());
    });
});


  • This selector contains the whole document of the body content.
Share it:

jQuery

Post A Comment:

0 comments: