jquery

jquery select object outside iframe

<script type="text/javascript">
jQuery('body').on('click','.close_menu',function(e) {
                 window.parent.jQuery('.menu_holder').hide();
})
</script>
By bm on January 22, 2014 | jquery | A comment?

jquery parent child

$(this).parent().find(‘.file_uplod_input’).click();

By bm on January 10, 2014 | jquery | A comment?

javascript to detect orientation and device

//orientation

var orientation =”;
var win_width = $( window ).width();
var win_height = $( window ).height()

if( win_width > win_height )
{
     $(“html”).removeClass(‘portrait’);
     $(“html”).removeClass(‘landscape’);

     $(“html”).addClass(‘landscape’);
     orientation=’landscape’;
}
else
{
     $(“html”).removeClass(‘portrait’);
     $(“html”).removeClass(‘landscape’);

     $(“html”).addClass(‘portrait’);

     orientation=’portrait’;
}
//device

var mob_min = 0;
var mob_max = 767;; /*480; /*600px; /*767px; /*480px;*/

var tab_min = mob_max;
var tab_max = 1024;

var pc_min = tab_max;

if(orientation==’landscape’)
{
     if(win_width <= mob_max)
     {
          set_device('MOBILE');
     }
     else if(win_width <= tab_max)
     {
          set_device('TAB');
     }
     else
     {
          set_device('PC');
     }
}
else
{
     if(win_height <= mob_max)
     {
          set_device('MOBILE');
     }
     else if(win_height <= tab_max)
     {
          set_device('TAB');
     }
     else
     {
          set_device('PC');
     }
}
By bm on | jquery | A comment?

is check box checked

if($(“#isAgeSelected”).is(‘:checked’))
     $(“#txtAge”).show(); // checked
else
     $(“#txtAge”).hide(); // unchecked

 

By bm on | jquery | A comment?

jQuery.get()

sysntax:-

jQuery.get( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

 

$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});

 

$.get( "ajax/test.html", function( data ) {
$( ".result" ).html( data );
alert( "Load was performed." );
});

 

$.get( "test.php", { name: "John", time: "2pm" } );

 

$.get( "test.php", { "choices[]": ["Jon", "Susan"] } );

 

$.get( "test.php", function( data ) {
alert( "Data Loaded: " + data );
});

 

$.get( "test.cgi", { name: "John", time: "2pm" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
});

 

$.get( "test.php", function( data ) {
$( "body" )
.append( "Name: " + data.name ) // John
.append( "Time: " + data.time ); // 2pm
}, "json" );
url
Type: String
A string containing the URL to which the request is sent.
data
Type: PlainObject or String
A plain object or string that is sent to the server with the request.
success(data, textStatus, jqXHR)
Type: Function()
A callback function that is executed if the request succeeds.
dataType
Type: String
The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
By bm on October 7, 2013 | ajax | A comment?

jQuery.post()

Description: Load data from the server using a HTTP POST request.

syntax:-

jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});

$.post( "ajax/test.html", function( data ) {
$( ".result" ).html( data );
});

$.post( "test.php", { name: "John", time: "2pm" } );

$.post( "test.php", { 'choices[]': [ "Jon", "Susan" ] } );

$.post( "test.php", $( "#testform" ).serialize() );

$.post( "test.php", function( data ) {
alert( "Data Loaded: " + data );
});

$.post( "test.php", { name: "John", time: "2pm" })
.done(function( data ) {
alert( "Data Loaded: " + data );
});

$.post( "test.php", { func: "getNameAndTime" }, function( data ) {
console.log( data.name ); // John
console.log( data.time ); // 2pm
}, "json");

<script>
// Attach a submit handler to the form
$( "#searchForm" ).submit(function( event ) {
	// Stop form from submitting normally
	event.preventDefault();
	// Get some values from elements on the page:
	var $form = $( this ), term = $form.find( "input[name='s']" ).val(), url = $form.attr( "action" );
	// Send the data using post
	var posting = $.post( url, { s: term } );
	// Put the results in a div
	posting.done(function( data ) 
	{
		var content = $( data ).find( "#content" );
		$( "#result" ).empty().append( content );
	});
});
</script>

 

url
Type: String
A string containing the URL to which the request is sent.
data
Type: PlainObject or String
A plain object or string that is sent to the server with the request.
success(data, textStatus, jqXHR)
Type: Function()
A callback function that is executed if the request succeeds. Required if dataType is provided, but can be null in that case.
dataType
Type: String
The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).
By bm on | ajax | A comment?