Jquery Example on YOUTUBE

35
http://www.youtube.com/kamleshutube  

Transcript of Jquery Example on YOUTUBE

Page 1: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 1/35

http://www.youtube.com/kamleshutube 

Page 2: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 2/35

SELECTORS / 1. BASIC

All Selector(“*”)  Selects all elements.

Class Selector (“.class”)  Matches all elements with the given name.

Element Selector (“element”)  Selects all elements with the given tag name 

ID Selector (“#id”)  Selects a single element with the given id attribute.

Multiple Selector (“selector1, 

selector2, selectorN”) 

Selects the combined results of all the

specified selectors.

Page 3: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 3/35

SELECTORS / 2. HIERARCHY

Child Selector (“parent > child”)  Selects all direct child elements specified by "child" of elements specified by "parent".

Descendant Selector (“ancestor 

descendant”) Selects all elements that are descendants of a given ancestor.

Next Adjacent

Selector (“prev + next”) 

Selects all next elements matching "next" 

that are immediately preceded by a 

sibling "prev".

Next Siblings Selector (“prev ~ 

siblings”) 

Selects all sibling elements that follow after the "prev" element, have the same parent, and match the filtering "siblings" selector.

Page 4: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 4/35

SELECTORS / 3. BASIC FILTER:eq() Selector Select the element at index n within the 

matched set.

:even Selector Selects even elements, zero-indexed 

:first Selector Selects the first matched element.

:gt() Selector Select all elements at an index greater than

index within the matched set.:header Selector Selects all elements that are headers, like

h1, h2, h3 and so on.

:last Selector Selects the last matched element.

:lt() Selector Select all elements at an index less than

index within the matched set.

:not() Selector Selects all elements that do not match the

given selector.

:odd Selector Selects odd elements, zero-indexed. See

also even.

Page 5: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 5/35

SELECTORS / 4. CONTENTFILTER

:contains() Selector Select all elements that contain the specified text.

:has() Selector Selects elements which contain at least one element that matches the specified selector.

:parent Selector Select all elements that are the parent of 

another element, including text nodes.

Page 6: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 6/35

SELECTORS / 5. ATTRIBUTE[attribute|=value] Selects elements that have the specified attribute with a

value either equal to a given string or starting with that stringfollowed by a hyphen (-).

[attribute*=value] Selects elements that have the specified attribute with avalue containing the a given substring.

[attribute~=value] Selects elements that have the specified attribute with avalue containing a given word, delimited by spaces.

[attribute$=value] Selects elements that have the specified attribute with avalue ending exactly with a given string.

[attribute=value] Selects all elements that are matched specified value

[attribute!=value] Select elements that either don't have the specified attribute,or do have the specified attribute but not with a certain value.

[attribute^=value] Selects elements that have the specified attribute with avalue beginning exactly with a given string.

[attribute] Selects elements that have the specified

attribute, with any value.

[attribute=value][attribute2=value2]

Matches elements that match all of the specified attributefilters.

Page 7: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 7/35

SELECTORS / 6. CHILD FILTER

:first-child Selector Selects all elements that are the first child of their parent.

:last-child Selector Selects all elements that are the last child of their parent.

:nth-child Selector Selects all elements that are the nth-child of their parent.

:only-child Selector Selects all elements that are the only child of their parent.

Page 8: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 8/35

SELECTORS / 7. FORM (contd.)

:button Selector Selects all button elements and elements of type button.

:checkbox Selector Selects all elements of type checkbox.

:checked Selector Matches all elements that are checked.

:disabled Selector Selects all elements that are disabled.

:enabled Selector Selects all elements that are enabled.

:file Selector Selects all elements of type file.

:image Selector Selects all elements of type image.

Page 9: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 9/35

SELECTORS / 7. FORM

:input Selector Selects all input, textarea, select and button elements.

:password Selector Selects all elements of type password.

:radio Selector Selects all elements of type radio.

:reset Selector Selects all elements of type reset.

selected Selector Selects all elements that are selected.

:submit Selector Selects all elements of type submit.

:text Selector Selects all elements of type text.

Page 10: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 10/35

EVENTS / MOUSE EVENTS (contd.) .click( handler(eventObject) ) Bind an event handler to the "click" JavaScript

event, or trigger that event on an element.

.dblclick( handler(eventObject) ) Bind an event handler to the "dblclick"

JavaScript event, or trigger that event on an

element.

.focusout( handler(eventObject) ) Bind an event handler to the "focusout"

JavaScript event.

.hover( handler(eventObject) ) Bind a single handler to the matchedelements, to be executed when the mousepointer enters or leaves the elements.

.mousedown( handler(eventObject)

)

Bind an event handler to the "mousedown"

JavaScript event, or trigger that event on an

element.

.mouseenter( handler(eventObject))

Bind an event handler to be fired when the

mouse enters an element, or trigger thathandler on an element.

Page 11: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 11/35

EVENTS / MOUSE EVENTS.mouseleave(handler(eventObject) ) Bind an event handler to be fired when the

mouse leaves an element, or trigger that handleron an element.

.mousemove(handler(eventObject) )

Bind an event handler to the "mousemove"

JavaScript event, or trigger that event on an

element.

.mouseout( handler(eventObject))

Bind an event handler to the "mouseout"

JavaScript event, or trigger that event on an

element.

.mouseover(handler(eventObject) )

Bind an event handler to the "mouseover"

JavaScript event, or trigger that event on anelement.

.mouseup( handler(eventObject))

Bind an event handler to the "mouseup"

JavaScript event, or trigger that event on an

element.

Page 12: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 12/35

EVENTS - FORM EVENTS

.blur( handler(eventObject) ) Bind an event handler to the "blur" JavaScript

event, or trigger that event on an element.

.focus( handler(eventObject) ) Bind an event handler to the "focus"JavaScript event, or trigger that event on anelement.

.change( handler(eventObject) ) Bind an event handler to the "change“

JavaScript event, or trigger that event on anelement.

.select( handler(eventObject) ) Bind an event handler to the "select"

JavaScript event, or trigger that event on anelement.

.submit( handler(eventObject) ) Bind an event handler to the "submit"JavaScript event, or trigger that event on anelement.

Page 13: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 13/35

EVENTS - EVENT OBJECT.pageX The mouse position relative to the left edge of the

document

.pageY The mouse position relative to the top edge of thedocument.

.type Describes the nature of the event.

.target The DOM element that initiated the event.

.preventDefault() If this method is called, the default action

of the event will not be triggered.

.isDefaultPrevented() Returns whether event.preventDefault() was evercalled on this event object.

.which For key or button events, this attribute

indicates the specific button or key that waspressed

Page 14: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 14/35

ATTRIBUTES - CLASS

.addClass( class ) Adds the specified class(es) to each of the set ofmatched elements.

.removeClass( class ) Remove a single class, multiple classes, or all

classes from each element in the set of matched

elements.

.hasClass( class ) Determine whether any of the matched elements are

assigned the given class.

.toggleClass( class, switch ) Add or remove one or more classes from each

element in the set of matched elements, dependingon either the class's presence or the value of the

switch argument.

Page 15: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 15/35

CSS - POSITIONING

.scrollLeft() Get the current horizontal position of the scroll bar

for the first element in the set of matched elements.

.scrollLeft( value ) Set the current horizontal position of the scroll bar for

each of the set of matched elements.

.offset() Get the current coordinates of the first element in the setof matched elements, relative to the document.

.offset( coordinates ) Set the current coordinates of every element in the

set of matched elements, relative to the document.

.position() Get the current coordinates of the first element in the setof matched elements, relative to the offset parent.

.scrollTop() Get the current vertical position of the scroll bar forthe first element in the set of matched elements.

.scrollTop( value ) Set the current vertical position of the scroll bar for

each of the set of matched elements.

Page 16: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 16/35

TRAVERSING -TREETRAVERSAL (cont.).children( [ selector ] ) Get the children of each element in the set of

matched elements, optionally filtered by a

selector

.closest( selector ) Get the first ancestor element that matches

the selector, beginning at the current

element and progressing up through theDOM tree.

.find( selector ) Get the descendants of each element in the

current set of matched elements, filtered by a

selector.

.next( [ selector ] ) Get the immediately following sibling of each

element in the set of matched elements,

optionally filtered by a selector.

.nextAll( [ selector ] ) Get all following siblings of each element in

the set of matched elements, optionally

filtered by a selector.

Page 17: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 17/35

TRAVERSING -TREETRAVERSAL (cont.)

.nextUntil( [ selector ] ) Get all following siblings of each elementup

to but not including the element matchedby

the selector.

.parent( [ selector ] ) Get the parent of each element in thecurrent

set of matched elements, optionally filtered

by a selector.

.parents( [ selector ] ) Get the ancestors of each element in the

current set of matched elements, optionally

filtered by a selector.

.prev( [ selector ] ) Get the immediately preceding sibling ofeach

element in the set of matched elements,

optionally filtered by a selector.

Page 18: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 18/35

TRAVERSING -TREETRAVERSAL (cont.)

.prevAll( [ selector ] ) Get all preceding siblings of each element in

the set of matched elements, optionally filtered

by a selector..prevUntil( [ selector ] ) Get the ancestors of each element in the

current set of matched elements, optionally

filtered by a selector.

.siblings( [ selector ] ) Get the siblings of each element in the set of

matched elements, optionally filtered by a

selector.

Page 19: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 19/35

TRAVERSING - FILTERING.eq( index ) Reduce the set of matched elements to the one at

the specified index.

.filter( selector ) Reduce the set of matched elements to those that

match the selector or pass the function's test.

.is( selector ) Check the current matched set of elementsagainst a selector and return true if at least one

of these elements matches the selector

.not() Remove elements from the set of matched

elements.

.slice( start, [ end ] ) Reduce the set of matched elements to a subset

specified by a range of indices.

.map( callback(index, domEl) ) Pass each element in the current matched set

through a function, producing a new jQuery

object containing the return values.

Page 20: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 20/35

TRAVERSING -MISCELLANEOUS

.add( selectors, [ context ] ) Add elements to the set of matched elements

.andSelf() Add the previous set of elements on the stack

tothe current set.

.contents() Get the children of each element in the set of

matched elements, including text nodes.

.end() End the most recent filtering operation in the

current chain and return the set of matched

elements to its previous state.

Page 21: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 21/35

ATTRIBUTES - ATTR.attr( attributeName ) Get the value of an attribute for the

first

element in the set of matchedelements.

.attr( attributeName,value )

Set one or more attributes for the setof

matched elements.

.removeAttr() Remove an attribute from each element

in the set of matched elements.

Page 22: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 22/35

ATTRIBUTES - HTML

.html() Get the HTML contents of the first

element in the set of matchedelements.

.html( htmlString ) Set the HTML contents of each

elementin the set of matched elements.

Page 23: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 23/35

ATTRIBUTES - TEXT

.text() Get the combined text contents of eachElement in the set of matchedelements,

including their descendants.

.text(textString )

Set the content of each element in theset of

matched elements to the specified text.

Page 24: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 24/35

ATTRIBUTES - VALUE

.val() Get the current value of the first element inthe set of matched elements.

.val( value ) Set the value of each element in the set of

matched elements.

Page 25: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 25/35

CSS - CSS

css( propertyName ) Get the value of a style property for

the first element in the set of

matched

elements.

.css( propertyName,

value)

Set one or more CSS properties for

the set of matched elements.

Page 26: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 26/35

CSS - HEIGHT & WIDTH (cont.).height( value ) Set the CSS height of every matched element.

element in the set of matched

elements.

.height() Get the current computed height for the first

.innerHeight() Get the current computed height for the first.

element in the set of matched elements,

including padding but not border.innerWidth() Get the current computed width for the first

element in the set of matched elements,

including padding but not border.

.outerHeight() Get the current computed height for the first

element in the set of matched elements,

including padding, border, and optionally

margin.

.outerWidth() Get the current computed width for the first

element in the set of matched elements,

including padding and border.

Page 27: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 27/35

CSS - HEIGHT & WIDTH

.width( value ) Set the CSS width of each element in the set of

matched elements.

.width() Get the current computed width for the first element inthe set of matched element

Page 28: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 28/35

MANIPULATION - INSIDE

.append( content ) Insert content, specified by the parameter, to the

end of each element in the set of matched

elements.

.appendTo( target ) Insert every element in the set of matchedelements to the end of the target.

.prepend( content ) Insert content, specified by the parameter, to the

beginning of each element in the set of matched

elements.

.prependTo( target ) Insert content, specified by the parameter, to theend of each element in the set of matched

elements.

Page 29: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 29/35

MANIPULATION - OUTSIDE

.after( content ) Insert content, specified by the parameter, after each elementin the set of matched elements.

.before( content ) Insert content, specified by the parameter, before eachelement in the set of matched elements.

.insertAfter( target ) Insert every element in the set of matched elements after thetarget.

.insertBefore( target ) Insert every element in the set of matched elements before

the target.

Page 30: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 30/35

MANIPULATION - AROUND

.wrap( wrappingElement ) Wrap an HTML structure around each element in

the set of matched elements.

.wrapAll( wrappingElement ) Wrap an HTML structure around all elements in

the set of matched elements.

.wrapInner( wrappingElement ) Wrap an HTML structure around the content of

each element in the set of matched elements.

Page 31: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 31/35

MANIPULATION - REPLACING

.replaceWith( newContent ) Replace each element in the set of matched elementswith the provided new content.

.replaceAll() A selector expression indicating which element(s) toreplace.

Page 32: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 32/35

EVENTS - HANDLERATTACHMENT (cont.).bind( eventType, [ eventData ], handler(eventObject) )

Attach a handler to an event for theelements.

.unbind( eventType, handler

(eventObject) )

Remove a previously-attached eventhandler from the elements.

.die() Remove all event handlers previously

attached using .live() from the elements.

.live( eventType, eventData, handler ) Attach a handler to the event for all

elements which match the current

selector, now or in the future.

.one( eventType, [ eventData ], handler

(eventObject) )

Attach a handler to an event for the

elements. The handler is executed at

most once per element.

Page 33: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 33/35

EFFECTS - BASIC

.hide( duration, [ callback ] )

Hide the matched elements.

.show( duration, [ callback ] )

Display the matched elements.

Page 34: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 34/35

EFFECTS - SLIDING

.slideDown( [ duration ], [ callback ] )

Display the matched elements with a sliding motion.

.slideToggle( [ duration ], [ callback ] )

Display or hide the matched elements with a sliding motion.

.slideUp( [ duration ], [ callback ] )

Hide the matched elements with a sliding motion.

Page 35: Jquery Example on YOUTUBE

8/4/2019 Jquery Example on YOUTUBE

http://slidepdf.com/reader/full/jquery-example-on-youtube 35/35

EFFECTS - FADING

.fadeIn( [ duration ], [ callback ] )

Display the matched elements by fading them to opaque.

.fadeOut( [ duration ], [ callback ] )

Hide the matched elements by fading them to transparent.

.fadeTo( duration, opacity, [ callback ] )

Adjust the opacity of the matched elements.