Two Ways of Starting A Jquery
Two Ways of Starting A Jquery
Two Ways of Starting A Jquery
Jquery declaration
1. $(document).ready(function() {
// your programming goes here
}); // end ready
2. $(function() {
// your programming goes here
}); // end ready
Types of selectors
1. ID selector
<p id="message">Special message</p>
to select the element
var messagePara = $('#message');
2. Element selector
var linksList = $('a')
selects all the <a> tag in the page and save it in a variable.
3. Class selector
$('.submenu')
4. Advanced selectors
a. Descendant selector
To target a tag inside another tag
$('#navBar a')
Here suppose a class navBar that has list of links this selects all those links
b. Adjacent sibling
Suppose a div tag followed by a heading h2 tag
$(‘h2 + div’)
Note: i guess this is useful when we don’t give any id or class name to the selector.
c. Attribute selector
Lets you select an element based on whether the element has a particular element.
[attribute]
$(‘a[href]’) selects <a> tags with link
[attribute=”value”]
$(‘input[type=”text”]’) selects element that have a particular attribute value, here this is
useful to select textbox
[attribute^=”value”]
$(‘a[href^=”https://”]’) selects element with attributes starting with https://
[attribute$=”value”]
$(‘a[href$=”.pdf”]’) selects element with attribute ending with .pdf
[attribute*=”value”]
$(‘a[href*=”missingmanual”]’) selects elements matching with missingmanual.com
Jquery Filters