Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery examples

jQuery examples


Do you want to improve your jQuery skills?


jQuery selector

$(this).hide()

Demonstrates the jQuery hide() function, hiding the current HTML element.

$("p").hide()

Demonstrates the jQuery hide() function, hiding all

.

$(".test").hide()

Demonstrates the jQuery hide() function, hiding all elements with class="test".

$("#test").hide()

Demonstrates the jQuery hide() function, hiding the element with id="test".


jQuery events

jQuery click()
Demonstrates the jQuery click() event.

jQuery dblclick()
Demonstrates the jQuery dblclick() event.

jQuery mouseenter()
Demonstrates the jQuery mouseenter() event.

jQuery mouseleave()
Demonstrates the jQuery mouseleave() event.

jQuery mousedown()
Demonstrates the jQuery mousedown() event.

jQuery mouseup()
Demonstrates the jQuery mouseup() event.

jQuery hover()
Demonstrates the jQuery hover() event.

jQuery focus() and blur()
Demonstrates the jQuery focus() and blur() events.

Example Parsing


jQuery Hide/Show

jQuery hide()
Demonstrates the jQuery hide() method.

jQuery hide() and show()
Demonstrates the jQuery hide() and show() methods.

jQuery toggle()
jQuery toggle() is used to toggle between the hide() and show() methods.

jQuery hide()
Another example of hiding text.

Example Parsing


jQuery Fade In/Out

jQuery fadeIn()
Demonstrates the jQuery fadeIn() method.

jQuery fadeOut()
Demonstrates the jQuery fadeOut() method.

jQuery fadeToggle()
Demonstrates the jQuery fadeToggle() method.

jQuery fadeTo()
Demonstrates the jQuery fadeTo() method.

Example Parsing


jQuery Sliding

jQuery slideDown()
Demonstrates the jQuery slideDown() method.

jQuery slideUp()
Demonstrates the jQuery slideUp() method.

jQuery slideToggle()
Demonstrates the jQuery slideToggle() method.

Example Parsing


jQuery Animation

jQuery animate()
Demonstrates a simple jQuery animate() method.

jQuery animate() - setting multiple CSS properties
Demonstrates changing styles with the jQuery animate() method.

jQuery animate() - using relative values
Demonstrates how to use relative values with the jQuery animate() method.

jQuery animate() - using predefined values
Demonstrates using the predefined "hide", "show", "toggle" values with the animate() method.

jQuery animate()
Demonstrates more jQuery animate() method examples

jQuery animate()
Demonstrates more jQuery animate() method examples (multiple animate() callbacks).

Example analysis


jQuery Stop Animation

jQuery stop() sliding
Demonstrates the jQuery stop() method.

jQuery stop() animation (with parameters)
Demonstrates the jQuery stop() method.

Example Parsing


jQuery HTML Get and Attributes

jQuery text() and html() - get text and content
Use the jQuery text() and html() methods to get content.

jQuery val() - get value
Use the jQuery val() method to get a form field's value.

jQuery attr() - get attribute value
Use the jQuery attr() method to get an attribute value.

Example Parsing


jQuery HTML set content and attributes

jQuery text(), html(), and val() - set content
Use the jQuery text(), html() and val() methods to set content.

jQuery text() and html() - set content with callback functions
Use text() and html() to set content with callback functions

jQuery attr() - set attribute value
Use the jQuery attr() method to set an attribute value.

jQuery attr() - set multiple attribute values
Use the jQuery attr() method to set multiple attribute values.

jQuery attr() - set attribute value with callback function
Set attribute value + call attr() with a callback function.

Example Parsing


jQuery HTML add elements/content

jQuery append()
Add content at the end of the selected element

jQuery prepend()
Add content at the beginning of the selected element

jQuery append() - insert multiple elements
Create new text/HTML elements, jQuery and JavaScript/DOM. Add after the new element text.

jQuery after() and before()
Add HTML elements before and after the selected element.

jQuery after() - insert multiple elements
Create new text/HTML elements, jQuery and JavaScript/DOM. Insert new elements at the end of the selected element.

Example Parsing


jQuery HTML remove elements/content

jQuery remove()
Remove the selected element

jQuery empty()
Remove all children of the selected element

jQuery remove() - using a parameter
Filter elements and remove

Example Parsing


jQuery Get and Set CSS Classes

jQuery addClass()
Add a class attribute to different elements

jQuery addClass() - multiple classes
Use the addClass() method to add multiple classes

jQuery removeClass()
Remove classes from the specified element

jQuery toggleClass()
Toggle (add/remove) classes on the selected element

Example Parsing


jQuery css() method

jQuery css() - return CSS property
Return the CSS property value of the first matched element

jQuery css() - set CSS property
Set the specified CSS property for all matched elements

jQuery css() - set CSS property
Set CSS properties for multiple matched elements

Example Parsing


jQuery dimensions

jQuery - return width() and height()
Return the width and height of the specified element

jQuery - return innerWidth() and innerHeight()
Return the inner-width/height of the specified element

jQuery - return outerWidth() and outerHeight()
Return the outer-width/height of the specified element

jQuery - return outerWidth(true) and outerHeight(true)
Return the outer-width/height of the specified element (including margins)

jQuery - return width() and height() of document and window
Return the width and height of the HTML document and window

jQuery - set width() and height()
Set the width and height of the specified element

Example Parsing


jQuery Traversing - Ancestors

jQuery parent()
Demonstrates the jQuery parent() method.

jQuery parents()
Demonstrates the jQuery parents() method.

jQuery parentsUntil()
Demonstrates the jQuery parentsUntil() method.

Example Parsing


jQuery Traversing - Descendants

jQuery children()
Demonstrate the jQuery children() method.

jQuery find()
Demonstrate the jQuery find() method.

Example Parsing


jQuery Traversing - Siblings

jQuery siblings()
Demonstrate the jQuery siblings() method.

jQuery next()
Demonstrate the jQuery next() method.

jQuery nextAll()
Demonstrate the jQuery nextAll() method.

jQuery nextUntil()
Demonstrate the jQuery nextUntil() method.

Example Parsing


jQuery AJAX load() Method

jQuery load()
Asynchronously load the content of a file and insert it into

element.

jQuery load()
Asynchronously load the specified element content from a file and insert it into

element.

jQuery load() - Using a Callback Function
Using the callback function of the jQuery load() method.

Example Parsing


jQuery AJAX get() and post() Methods

jQuery get()
Use the $.get() method to asynchronously fetch data from the server

jQuery post()
Use the $.post() method to asynchronously fetch data from the server

Example Parsing


Other Examples

jQuery Dynamic Particle Effect