sQuery - a mini library for selecting DOM elements
JavaScriptMIT
sQuery
sQuery - a mini library for selecting DOM elements
Note "sQuery" is just my remake of famous DOM selector ... Stable version: 1.5 + fix - sQuery.js Minified: 1.5 + fix - sQuery.min.js
Usage
Step 1 Include the `sQuery.js` file in your html head tag.
<head><scriptsrc="sQuery.js"></script></head>
Step 2 Run the sQuery file after the documents or window loads.
You can give it a name of your own. Like creating a new function constructor.
// sQuery v1.0function$(e){returnnewsQuery(e);}window.onload=function(){$("p").text("Hello");};// NOW sQuery v 1.1.1 and above now supports .ready() methodsQuery("document").ready(function(){//code here});
List of properties and methods
.ready(function()...)
executes a function once the DOM was ready
best use with document
.call(function(element)...)
accepts a function and then executes the function for the element selected.
the function must contain also a param that would accept the elements to come.
.html(string)
accepts a string
changes the innerHTML of element to the specified string
returns the html of the selected element if param is empty
.text(string)
accepts a string
changes the innerText of element to the specified string
.value(string)
accepts a string
changes the value of element to the specified string
.color(string)
changes the color of the element to the specified string
.on("event",function()...)
adds an event to the corresponding function
returns false to prevent popping, bubbling etc...
.toggle()
toggles the current display of the element to either none or block
.txt()
returns the innerText of the selected element
.val()
returns the value of the selected element
.css(property,value)
changes the assign style property to the element with the given value