Follow by Email

JQuery Introduction & JQuery Search Characters



We mainly use J Query for searching for some items on the page & doing something with them .

The JQuery functions which finds the items on the page are called selectors.

Base Selector in J Query is JQuery() or $() function.

String arguments can be passed to this functions in three ways 
 
Select by Element: This finds the elements with specific tag name & returns the array of that.
E.g.: $(“h2”) – this will find all <h2> tags.

Select by ID: This finds the elements which has the specified ID. We use “#” character to find the ID.
E.g.: 1) $(“#div1”) ---then this will search the elements which have the ID=div1.  
         2) If you want to search the element <div ID=”mydiv”> then JQuery would be $(“#mydiv”).

Select by CSS: this finds the elements with specific CSS class names. We use “.” to find the CSS class.
E.g.: 1) $(“.divStyle”) ---then it will search for the element which has CSS class as divStyle.
         2) If we want to search for the element <div class=”myDiv”> then JQuery will be $(“.myDiv”).

1.
There are some search characters used in JQuery to find the specific elements.

1.       “*” (asterisk) character: This is used to search the specified search term in the elements.
E.g.: $(“a[href*=net]”) ---- this will search in all <a> tags which has the text “net” as the part of the href attribute.

2.       “^” (caret) character: This is used to search the specified search term at the starting of the string.
E.g. $(“a[href^=folder/]”) ---- This will search in all <a> tags which has the text “folder/” at the beginning of the href attribute.

3.       “$” (dollar) character: This is used to search the specified search term at the end of the string. 
      E.g. $(“a[href$=in]”) ---- This will search for all <a> tags which has the text “in” at the end of the href      attribute.

4.       “!” (exclamation) character: This is used to search the elements whose attributes do not match the specified string 
      E.g.: $(“a[href!==http://www.google.com]”) ---- This will search for all <a> tags whose href attribute is not equal to www.google.com

0 comments:

Post a Comment