Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Overview of how JQuery selects HTML elements on the page

March 31, 2015 Leave a Comment

Installing jQuery Library

For jQuery code to work you need to install the jQuery library in the head of your web page document, WordPress and other CMS’es already come with it pre-installed so make sure not to double up.

Get the latest jQuery here. There are 2 versions, the v2 version has no support for IE 6, 7, 8 whilst v1 version does. Use the one more suitable version to your target browser audience.

Download the production version and reference it in the head of your document.

<script src="/js/jquery-1.11.1.min.js"></script>

 

When does jQuery execute?

jQuery uses the document.ready event to execute or fire it’s code, document.ready is available once the DOM of the page has loaded which is before the actual contents of the page are loaded.

You can use multiple occurrences of this event which jQuery will run in succession. This approach is favourable to the traditional window.onload event which only executes once all the page content has downloaded.

document.ready

The document.ready event is written out like so…

    $("document").ready(function() {
    //code goes here
    
    });

Selecting HTML elements on the page

If you are familiar with CSS, then jQuery selection techniques should seem familiar.

 

Selecting a HTML tag element, for example all the <p> tags on the page:

   $("document").ready(function() {
    $("p");
    });

 

Selecting based on a CSS class or ID would be:

   $("document").ready(function() {
    $(".classname");
    });

 

Selecting based on HTML Tag and classname or ID:

   $("document").ready(function() {
    $("p.classname");
    });

 

Selecting multiple elements require the elements to be comma separated:

   $("document").ready(function() {
    $("ul,p");
    });

 

Select descending elements is with one element following another; parent child:

   $("document").ready(function() {
    $("ul li");
    });

 

Select adjacent element is with a ‘+’:

   $("document").ready(function() {
    $("ul+p");
    });

 

Select direct child elements of parent element is with a greater than sign:

   $("document").ready(function() {
    $("ul > li");
    });

 

Select like elements that come after another element:

   $("document").ready(function() {
    $("ul ~ p");
    });

Part 2 will deal with Filtering HTML elements with jQuery.

Cats: WebDev Tags: jquery

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Discuss

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls
Get DesktopServer

Lynda

Lynda.com Online Training Videos

TreeHouse

smlinks

Learn WordPress
osx-modify-shell-path

How to Add to the Shell Path in macOS Big Sur and Catalina using Terminal

October 19, 2019

virtual-hosts osx 10.10 yosemite

Set up Virtual Hosts on macOS Catalina 10.15 in Apache

October 19, 2019

Installing Homebrew on macOS Catalina 10.15, Package Manager for Linux Apps

October 18, 2019

Where is the bash shell in macos Catalina?

October 12, 2019

Refine your search

  • All
  • Modules
  • Themes
  • Documentation
  • Forums & Issues
  • Groups

RSS ars technica

  • Apple and Meta furious at EU over fines totaling €700 million
  • After market tumult, Trump exempts smartphones from massive new tariffs
  • Apple silent as Trump promises “impossible” US-made iPhones
  • Apple enables RCS messaging for Google Fi subscribers at last
  • EU will go easy with Apple, Facebook punishment to avoid Trump’s wrath

RSS mac surfer

  • Tot is new text editor for Mac, iPhone, and iPad focused on constraints and ease of use
  • TiPbITS: Google Drive Sorting Can Hide New Documents
  • How to take a screenshot on a MacBook Pro
  • How To Create Simple Animation With Mac Keynote
  • Last Week on My Mac: Virus pandemics

Donate

Copyright © 2025· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2025 · gee on Genesis Framework · WordPress · Log in