April 16 2018

CSS and Jquery Android click Ripple effect look like

Tagged Under : , ,

css3
Below are showing example Android click Ripple effect with CSS3 and Jquery.
Below was 2 example:
Example 1
Example 2

March 26 2017

Jquery set focus on last character in input text box

Tagged Under :

javascript
Normally using Jquery or Javascript to set focus on input box it will point to beginning of the text box. But if you want it point to last character in input text box. you may need write a Jquery class to do.

Below is the Jquery function:
(function($){
    $.fn.focusTextToEnd = function(){
        this.focus();
        var $thisVal = this.val();
        this.val('').val($thisVal);
        return this;
    }
}(jQuery));

You may easy to use the function like below
$("#input").focusTextToEnd();

December 13 2016

Jquery validation validate money method function

Tagged Under :

javascript
Jquery validation itself didn’t give money validate method function. What we can to do is write a custom method to validate the money format with regular expression.

Below is the money validate method.
jQuery.validator.addMethod(
    "money",
    function(value, element) {
        var isValidMoney = /^\d{0,4}(\.\d{0,2})?$/.test(value);
        return this.optional(element) || isValidMoney;
    },
    "Insert "
);

August 29 2016

Jquery find the specific Id if exists

Tagged Under :

javascript
If want to check the specific Id already exists inside the site. you may using “length” to do it.

For Example:
if( $('#selector').length) {
     // it exists
}
if the length more then 0, that’s mean the following Id already exists inside the site.

if you are using class to check
if( $('.selector').length) {
     // it exists
}

February 16 2016

WordPress Ajax Example

Tagged Under : , ,

Wordpress
Below is the basic example of how to use AJAX in WordPress. It show you how to using javascript pass the variable to PHP function and then return back to javascript.

Javascript
var ajaxurl = '<?php echo admin_url() ?>admin-ajax.php';
jQuery(document).ready(function () {
	jQuery.ajax({
		url: ajaxurl,
		data: {
			//This action must same with the PHP function name
			"action": "ajax_request",
			"params": "wordpress ajax"
		},
		success:function(data) {
			//This is the result return from PHP function
			console.log(data);
		},
		error: function(errorThrown){
			//This is the error return
			console.log(errorThrown);
		}
	});
});

February 16 2016

Jquery only allow numeric (0-9) in HTML inputbox

Tagged Under :

jquery

Below is the function I use to only number, delete, backspace and tap are allow.
$(document).on("keydown", "#number", function(e) {
	var key = e.charCode || e.keyCode || 0;
	
	if (key == 8 || key == 9 || key == 13 || key == 46 || key == 110 || key == 190 || (key >= 35 && key <= 40) ||(key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
		return;
	} else {
		return false;
	}
});

February 04 2015

Jquery simple dynamic dropdown options with PHP array

Tagged Under : ,

jquery
Dynamic dropdown options always use in our Application. It can be based on user first selection to return a new listing to second dropdown options by AJAX.

Below is the example PHP array script:
$option = array();
$option[] = array('name' => 'fruits', 'value' => 'f');
$option[] = array('name' => 'vegetables', 'value' => 'v');
$option[] = array('name' => 'pizza', 'value' => 'p');

And now we need the Jquery script to build the dropdown select. Below script are allow to reuse again when you need to replace the dropdown option again.

October 19 2014

Jquery position popup a div near the cursor mouse pointer

Tagged Under :

jquery
Below image was showing you display a div beside the mouse pointer or cursor. when user click the relative text.
div popup
Click Here to check how the code work.

July 22 2014

Jquery Smooth Scroll to an Element Without Using Plugin

Tagged Under :

jquery
Jquery provide a lot of useful plugin. But sometimes you are allow using pure jQuery to complete the feature.

Below example code showing how to using pure jQuery to completed scroll to element feature.
JQuery smooth scroll example code

January 15 2014

Jquery plugin tablesorter filter match how to

Tagged Under :

jquery
Jquery tablesorter is a powerful plugin for table sort and filter. It help me completed a lot of stuff.

But I found a problem, when I want filter by exact match results, the default filter function cannot do this. And I try add “filter-match” classes to the “th” header cells. Unfortunately the results return still same.

The Solution:
To filter by exact match, you may need modify or add “filter_functions” at the “widgetOptions“. The example: