Simple and lightweigh jQuery replacement. Using the same API with jQuery.
npm install mjQuery
Globally exported as $
, mjQuery
and jQuery
$(selector)
selector
can be:
String
Node
NodeList
HTMLElement
HTMLCollection
- or another mQuery instance.
$(selector).show() # Set display to none
$(selector).hide() # Clear display css attribute
$(selector).addClass(className)
$(selector).removeClass(className)
$(selector).hasClass(className)
$(selector).toggleClass(className)
$(selector).css(cssClassname, cssValue)
$(selector).val() # Get value of input
$(selector).val(value) $ Set value to input
$(selector).attr(attrName)
$(selector).attr(attrName, value)
$(selector).removeAttr(attrName)
$(selector).prop(propName)
$(selector).prop(propName, value)
$(selector).on(eventName, eventHandler);
$(selector).click(eventHandler);
$.ajax(url, options)
$.ajax(options)
options
is a plain javascript object. Supported options:
url
: The request URLmethod
: Request method. Eg: GET, POST, PUT, DELETE...data
: Data to send with request. Can be object or URLEncoded stringsuccess
: Function called on success (200 <= statusCode < 400)error
: Function called on failed
$.param(obj) # Return URLEncoded query string
$.clone(obj) # Clone an object
MIT