Git Product home page Git Product logo

gquery's Introduction

#gQuery

Setup

First you have to download gQuery.js for development or gQuery-min.js for common usage.

gQuery.js

The next step is to include the gQuery.js or gQuery-min.js file in your application. For example:

<script src="http://example.com/gQuery.js"></script>

Usage

Here we are gonna show how you can use it.

Initialize elements

// Selecting class(es):
var myElement = $(".myelement");

// Selecting id(s).
var myElement = $("#myelement");

For more examples, follow - http://www.w3.org/TR/selectors-api/#examples0

Class manipulating

var myElement = $(".myelement");

// Check if the element has class
var hasclass = myElement.hasClass("hasthisclass"); // Returns boolean[true|false]

// Remove class(es)
myElement.removeClass("removethisclass"); 
myElement.removeClass("removethisclass andremovethisclass thistoo"); // Can remove multiple classes at once

// Add class(es)
myElement.addClass("addthisclass");
myElement.addClass("addthisclass andthisclass"); // Can add multiple classes at once
myElement.addClass("addthisclass").addClass("addthistoo"); // Multiple functions supported

// Toggle class
myElement.toggleClass("togglethis");

Cosmetics

var myElement = $(".myelement");

// Show element(s)
myElement.show();

// Hide element(s)
myElement.hide();

// Remove element(s) completely
myElement.remove();

// Change css
myElement.css("background-color: #FAFAFA; color: #333;");

Events

var myElement = $(".myelement");

// Add event
myElement.on("click", function() {
   // Do something
});

// Remove event
myElement.off("click", function() {
   // Do something
});

// Click shortcut
myElement.click(function() {
   // Do something when clicked
});

AJAX

// Get JSON file
$.ajax({url: "example.json", onsuccess: jsonSuccessFunction, onerror: ajaxError });

// Get HTML file
$.ajax({url: "example.html", onsuccess: htmlSuccess, onerror: ajaxError });

// Post
$.ajax({url: "target.php", type: "POST", data: {user: "Indloon", password: "DidyoureallyathinkIwouldtypemypasswordhere?"}, onsuccess: jsonSuccessFunction, onerror: ajaxError });

// Functions used in ajax query.
var htmlSuccess = function() {
   // Do something
};

var jsonSuccessFunction = function() {
   // Do something
};

var ajaxError = function() {
   // Do something
};

Footnotes

What is this?

gQuery is jQuery like DOM library which targets at use of core functions like basic manipulation of classes (addClass, toggleClass...etc.) and even use of jQuery like simple AJAX query and all that with using native methods. Theoretically it should work with IE8 and above along with all browsers that support at least document.querySelectorAll.

Also, gQuery is WIP (work-in-progress), hence why only core functions are supported. I will add the function that I like to see or even better, pull a request for functions you like to see.

Why?

This is not meant to compete against jQuery or any other well-known library but this is more like for studying purposes and for playing around.

Licence

gQuery is an open-source project and therefore it uses GPL v2.

gquery's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.