|
jQuery
Input Placeholder Handling for Incompatible Browsers with jQuery »
|
jQuery(function($){
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
$('[placeholder]').parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
}); |
|
jQuery
Prevent right-click context menu on images with jQuery »
|
jQuery(function ($){
$('img').live('contextmenu', function(e){
alert('These images are copyright [COMPANY] and may only be used with explicit permission.');
return false;
});
}); |
|
jQuery
Smoothscroll for anchor links with jQuery »
Many thx:...
|
jQuery(function ($) {
var SMOOTHSCROLL_MARGIN = 12;
$(".smoothscroll").click(function(evt){console.log('s');
evt.preventDefault();
var offset = $($(this).attr('href')).offset().top - SMOOTHSCROLL_MARGIN;
$('html, body').animate({scrollTop:offset}, 500);
});
}); |
|
jQuery
jQuery quick outer HTML on an element »
|
// DNF the '<' '>' chars !!
$(ele).wrap('<div>').parent().html(); |
|
jQuery
Check whether HTML5 is handled correctly »
|
// IE8- doesn't do element creation well in jQuery
function handlesHTML5Correctly()
{
return ( $('<figure><img src="#" /></figure>').length == 1 );
} |