Tag Archives: jQuery

How to display fields using select drop down and jQuery

  <script type="text/javascript">     $(document).ready(function(){         $("#Select").change(function(){             if ($(this).val() == "Other" ) {                 $("#OtherField").show();             } else {                 $("#OtherField").hide();           [...]
Posted in jQuery | Also tagged , , , , , | Leave a comment

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 , , , , , | Leave a comment

Simple and Smooth Expand and Collapse with jQuery

HTML example   <h2 class="myClass" id="trigger1">Click here to expand</h2> <div class="hide-container">      <p>Here goes whatever you want to expand/collapse</p>      <p>Here goes whatever you want to expand/collapse</p>      <p>Here goes whatever you want to expand/collapse</p>      <p>Here goes whatever you want to expand/collapse</p> </div>   CSS   .myClass {font-size:20px; color: #FF0000;} [...]
Posted in jQuery | Also tagged , , , | 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   [...]
Posted in jQuery | Also tagged | Leave a comment

How to Scroll to the Top Smoothly with jQuery

jQuery   $(document).ready(function() {         $(‘.backtotop’).click(function(){                 $(‘html, body’).animate({scrollTop:0}, ‘slow’);         }); });  
Posted in jQuery | Also tagged , , , , | 1 Comment

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 [...]
Posted in jQuery | Also tagged , , , , , | Leave a comment

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");  
Posted in jQuery | Also tagged , , | Leave a comment

How to Collapse and Expand with jQuery

Inside HEAD   <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(function() {   $("#trigger").click(function(event) { event.preventDefault(); $("#box").slideToggle(); });   $("#box a").click(function(event) { event.preventDefault(); $("#box").slideUp(); }); }); </script>   HTML:   <a href="#" id="trigger">TRIGGER</a> <div id="box"> <a href="#" class="close">[x]</a> <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna [...]
Posted in jQuery | Also tagged , | Leave a comment

How to Display Latest Tweet

  $.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?", function(data) {      $("#twitter").html(data[0].text); });  
Posted in jQuery | Also tagged , , | 2 Comments

How to Check if Element Exists

  if ( $(‘#myElement’).length > 0 ) {     // it exists }  
Posted in jQuery | Also tagged , , | Leave a comment