Pages

Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Thursday, June 15, 2017

Event.stopPropagation() and Event.preventDefault()



1. event.stopPropagation() stops an event from bubbling up the event chain

2. event.preventDefault() will only prevent browser’s default action on that event from occurring, but the event still propogates up the event chain.


Example

$("#myDiv").click(function() {
   alert('click on #myDiv');
});

$("#divButton").click(function(e) {
   alert('button click');
   e.stopPropagation();
});

Thursday, October 20, 2011

Detecting an undefined object in JavaScript


typeof allows the identifier to never been declared before
if (typeof obj == "undefined")
instead of
if(obj == null) // will throw an error due to never declared


Wednesday, August 31, 2011

How to stop caching with jQuery ($.get(), $.ajax() etc) and javascript



To make it unique for each passes, we can place in a random number behind the url as shown below
$.get('remoteUrl.do?'+Math.random()+, function(data){
	$('#msg'+id).html(data);
}, 'html');


Set cache:false 
$.ajax({
	url: 'remoteUrl.do',
	cache: false,
	success: function(data){
		$('#resultDiv').append(data);
	} }); 
$.ajaxSetup({
	cache: false
});
Disable caching using html meta tag:

Friday, July 10, 2009

JQuery

jQuery is a Open source JavaScript Library.

jQuery is easy to learn.

Fast, Easy to use, Easy-to-use AJAX (I love the $.ajaxSetup() function)
Nice Event handlers
CSS selectors


features:

* HTML element selections
* HTML element manipulation
* CSS manipulation
* HTML event functions
* JavaScript Effects and animations
* HTML DOM traversal and modification
* AJAX
* Utilities

Google
 

Java-Struts