Section 7 - Odds and Ends

Diving into the Source Code of Jquery

  • Motive: Borrow new ideas from well developed code.

  • Jquery:

    • js library

    • Makes it easily to write things syntactically.

    • Handles cross browser compatability.

    • Manipulates HTML (the DOM)

  • How it works

    • $ invokes functionality of the library (just like _ in underscore).

  • Basics

People

  • John Doe

  • Jane Doe

  • Jim Doe

    var a = $("ul");
    var b = $("ul.people");
  • Grabs all ul html elements

  • Grabs all ul elements with attribute class 'people'

  • In general, the way we query elements in jquery is essentially the same way we do in CSS.

    • Includes a whole entire library for this (sizzle.js).

    var c = $("ul.people li");
    console.log(c);
  • We can notice a few things.

    • Array containing list elements

    • Standard html DOM elements

    • and the proto derivation, that lists all the methods associated with the object variable.

  • addClass() method, add html class element.

    • removeClass()

      • Method chaining

        • object.method1().method2() both affect the parent object.

        • returns this on a method.

    var b = $("ul.people").addClass('newclass'),removeClass('people');
    <ul class="newclass"> ... </ul>

Last updated

Was this helpful?