Q.js Documentation

Download

You can download the Development Version or the Production Version. Both versions are currently provided under both MIT License and CC0 Public Domain Dedication.

Selector: $()

In order to manipulate or create a DOM element, you must describe it by wrapping it with the $() function. $ accepts three types of object:

  1. String HTMLSource. A string starting with < and ends with >, signifying the source of an HTML element. For example,
    $("<div class='info'>Hello World</div>")

    This code generates and saves a <div> element inside Thing object. In order to insert this element into the document, you must .prepend, .append or use another method to manually tell Thing where it should be.

  2. String selector. A CSS selector matching a single or multiple elements in the document. Thing.js does not complain when there is no match.
    $("#form input[type='input']")
    In order to use the CSS selector, document.querySelectorAll must be present. For Internet Explorer 7 or earlier version, include this polyfill script (508 bytes, 301 bytes gzipped).
  3. HTMLElement Element. A DOM element, usually returned from a native method to select elements, like document.getElementById()
    $(document.head)
    $(document.getElementsByTagName('span'))

.attr()

.attr(String attributeName)

This method returns the attribute value.

.attr(String attributeName, Any attributeValue)

This method sets the attribute value.

Example:
<img id="logo" alt="My Logo" src="/img/logo.png">$('#logo').attr('alt') // "My Logo"
$('#logo').attr('alt', 'Company Logo'); // alt="Company Logo"

.addClass()

.addClass(String className)

This method adds one or more class to the element(s). If there are more than one class, they should be separated by space. If an element already has the given class, it will be ignored.

.append()

.append(String HTMLSource)
.append(String Selector)
.append(HTMLElement Element)

This method appends the given element to the selected elements.

.removeClass()

.removeClass(String className)

This method removes one or more class from the element(s). If there are more than one class, they should be separated by space. If an element doesn’t have the given class, it will be ignored.