Table Of Contents

aps/query

This module provides DOM querying functionality. The module exports a function that can be used to query for DOM nodes by CSS selector and returns a ``NodeList`` representing the matching nodes.

Return: dojo/nodelist

Table of contents

Compatibility

All user panels - CP and UX1

Example

The following code adds an onclick handler to every submit button and thus replaces the default handler in order to send the form via Ajax:

require(["aps/query", "dojo/request", "dojo/dom-form", "dojo/dom-construct", "dojo/dom-style"],
   function(query, request, domForm, domConstruct, domStyle){
      query("input[type='submit']").on("click", function(e){
         e.preventDefault(); // prevent sending the form
         var btn = e.target;
         request.post("http://example.com/", {
            data: domForm.toObject(btn.form)
         }).then(function(response){
            // replace the form with the response
            domConstruct.create(div, {innerHTML: response}, btn.form, "after");
            domStyle.set(btn.form, "display", "none");
         });
      });
});

Parameters

ARGUMENT

TYPE

DESCRIPTION

selector

String

A CSS selector to search an object for.

context

String
DomNode

An optional context to limit the searching scope. Only nodes under the specified context will be scanned.