Categories
Friends
Links
Tag Archives: jQuery
How to Show/Hide a div based on day of the week with jQuery
JavaScritpt <script type="text/javascript"> $(document).ready(function() { today=new Date() thisDay=today.getDay() $("#sunday").hide(); $("#monday").hide(); $("#tuesday").hide(); [...]
Posted in JavaScript, jQuery Also tagged date, day of week, getDay, hide, JavaScript, show Leave a comment
Character Count with jQuery
jQuery $(‘textarea’).each(function(){ // get current number of characters var length = $(this).val().length; // get current number of words //var length = $(this).val().split(/\b[\s,\.-:;]*/).length; // update characters $(this).parent().find(‘.counter’).html( 4000 – length + ‘ characters left’); // bind on key up event [...]
How to Scroll to the Top Smoothly with jQuery
jQuery $(document).ready(function() { $(‘.backtotop’).click(function(){ $(‘html, body’).animate({scrollTop:0}, ‘slow’); }); });
How to Scroll to Anchor Links Smoothly with jQuery
jQuery $.fn.scroller = function() { var speed = ‘slow’; // Choose default speed $(this).each(function() { $(this).bind(‘click’, function() { var target = $(this).attr(‘href’); // Get scroll target [...]
Preloading Images with jQuery
jQuery jQuery.preloadImages = function() { for(var i = 0; i<arguments.length; i++) { jQuery("<img>").attr("src", arguments[i]); } }; // use like $.preloadImages("image0001.jpg", "/path/to/image0002.jpg", "some/image0003.jpg");
How to Display Latest Tweet
$.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?", function(data) { $("#twitter").html(data[0].text); });
How to Check if Element Exists
if ( $(‘#myElement’).length > 0 ) { // it exists }
How to display fields using select drop down and jQuery