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 feed: ars technica ars technica

  • Vulnerability giving attackers full control of Macs is under active exploitation
  • OpenAI says Apple's trade secrets lawsuit is "aggressive and oddly personal"
  • Tim Cook passes the baton in Apple's Q3 2026 earnings call
  • San Francisco orders Apple, Google to remove nudify apps from app stores
  • Apple sues OpenAI after ex-engineer allegedly used bug to steal trade secrets

RSS feed: mac surfer mac surfer

  • Apple Cuts 200+ Jobs Across Vision Pro and Siri Teams
  • Walmart Finally Accepts Apple Pay in US Stores
  • 'The Dynasty: UConn Huskies' Premieres on Apple TV
  • Apple Music to Label AI-Generated Tracks
  • Apple Watch ECG Saves Triathlete's Life

Donate

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

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