Set a Timer

The following piece of code can be used to set a timer using jQuery: $(document).ready(function() { window.setTimeout(function() { // some code }, 500); });

Read More

Check if an Element Is Visible

To check whether an element is visible, you can use the following piece of code: if($(element).is(“:visible”) == “true”) { //The DOM element is visible } else { //The DOM element is invisible }

Read More

Check if an Element Exists

To check whether an element exists, you can write the following code: if ($(“#someElement”).length) { //The DOM element exists } else { //The DOM element doesn’t exist }

Read More

Detect Current Mouse Coordinates

Now, suppose you need to detect the current mouse coordinates in the web browser in use. To do this, you can write the following piece of code: $(document).ready(function() { $().mousemove(function(e) { $(‘# MouseCoordinates ‘).html(“X Axis Position = ” + e.pageX + ” and Y Axis Position = ” + e.pageY); }); });

Read More

Get & Set

Get & Set Textbox Values: //— GET & SET TEXTBOX VALUE —// //— CAN ALSO BE USED ON ANY OTHER ELEMENT THAT HAS A VALUE PROPERTY —// // get the value of a textbox var TextboxValue = $(“#TextboxID”).val(); // set the value of a textbox $(“#TextboxID”).val(“New Textbox Value Here”); Get & Set Element’s HTML: //— […]

Read More

Add & Remove CSS Classes

// add css class $(“#DivID”).addClass(“newclassname”); // remove css class $(“#DivID”).removeClass(“classname”); // add & remove class together $(“#DivID”).removeClass(“classname”).addClass(“newclassname”); // add & remove multiple classes $(“#DivID”).removeClass(“classname classname2”).addClass(“newclassname newclassname2”);

Read More

Animate Functions

//— ANIMATE (EXAMPLE USES OPACITY, BUT CAN USE ANY CSS PROPERTY. —// //— NOTE SOME MY REQUIRE THE USE OF A PLUGIN SUCH AS JQUERY COLOR ANIMATION PLUGIN. —// $(“#DivID”).animate({ opacity: 0.25 }, 1000); // do something when animation complete $(“#DivID”).animate({ opacity: 0.25 }, 1000, function () { alert(“Opacity Animation Complete”); });

Read More

Slide Functions

// toggle slide up and down $(“#DivID”).slideToggle(1000); // do something when animation complete $(“#DivID”).slideToggle(1000, function () { alert(“Slide Toggle Complete”); }); // slide up $(“#DivID”).slideUp(1000); // do something when animation is complete $(“#DivID”).slideUp(1000, function () { alert(“Slide Up Complete”); }); // slide down $(“#DivID”).slideDown(1000); // do something when animation is complete $(“#DivID”).slideDown(1000, function () { […]

Read More

Fade Functions

// fade in $(“#DivID”).fadeIn(1000); // do something when animation complete $(“#DivID”).fadeIn(1000, function () { alert(“Fade In Complete”); }); // fade out $(“#DivID”).fadeOut(1000); // do something when animation is complete $(“#DivID”).fadeOut(1000, function () { alert(“Fade Out Complete”); }); // fade to (fades to specified opacity) $(“#DivID”).fadeTo(1000, 0.25); // do something when animation is complete $(“#DivID”).fadeTo(1000, 0.25, […]

Read More