facebook@jsbanktwitter@js_bankgoogle+javascriptbanknewsletterrss@jsbank
Guest, register






ieoBIN.com - The Best IEO List to Discover, Invest in 2019

Efficient and Helpful JavaScript/jQuery Tips and Tricks This free HTML JavaScript tutorial provides 45+ JavaScript/jQuery tips and tricks that help you work in JavaScript tasks better, through live HTML JavaScript example codes. List of some JavaScript tips and tricks:

- Refreshing the src of an image with jQuery?
- Check if an image is loaded or not with jQuery
- Remove selected text after mouse double click JavaScript event
- Validate an email address
- Check if an HTML control element exists
- Cancel an AJAX request
- Select all HTML checkboxes
- Selecting root element of a certain level in the document
- Searching a string in jQuery

Please go to the full post page for full detailed tips and HTML JavaScript example codes, then try some JavaScript tutorials:

- 10 Small Javascript Tricks You Should Master
- Some Basic Tips and Tricks for Speeding Up JavaScript
- 10 jQuery and JavaScript Tips and Tricks to Improve Your Code
- 5 Good and Small JavaScript Tips and Tricks


  • Moving options from list A to list B
  • 1.$().ready(function() {
    2.    $('#add').click(function() {
    3.        !$('#select1 option:selected').appendTo('#select2');
    4.    });
    5.    $('#remove').click(function() {
    6.        !$('#select2 option:selected').appendTo('#select1');
    7.    });
    8.});
  • Select all checkboxes
  • 1.$(document).ready(function(){
    2.    $("#checkboxall").change(function(){
    3.        var checked_status = this.checked;
    4.        $("input[name=checkall]").attr("checked", checked_status);
    5.    });
    6. 
    7.});
  • Get the current URL
  • 1.$(document).ready(function() {
    2.    var pathname = window.location.pathname;
    3.});
  • Check if and which key was pressed
  • 01.$(function() {
    02.    $(document).keypress(function(e){
    03.        switch(e.which){
    04.        // "ENTER"
    05.        case 13:
    06.        alert('enter pressed');
    07.        break;
    08. 
    09.        // "s"
    10.        case 115:
    11.        alert('s pressed');
    12.        break;
    13. 
    14.        (...)
    15. 
    16.        }
    17.    });
    18. 
    19.});
  • How to hide all children div except a specific one with jQuery?
  • 1.$('#target div:not(#exclude)').hide();
    2.//or
    3.$('#target').children().filter(':not(#exclude)').hide();
  • Detecting when a div's height changes using jQuery
  • 1.$('element').bind('resize', function(){
    2.alert( 'Height changed to' + $(this).height() );
    3.}
  • Delete all table rows except first
  • 1.$('someTableSelector').find('tr:gt(0)').remove();
  • Selecting root element of a certain level in the document
  • 1.1 level:
    2.$('*:not(* *)');
    3.2 level:
    4.$('*:not(* *)').find('> *');
    5.3 level:
    6.$('*:not(* *)').find('> * > *');
  • Searching a string in jQuery
  • 1.var foundin = $('*:contains("some string bla bla")');
  • Get the distance scrolled from top
  • 1.alert($(document).scrollTop());

    JavaScript by day


    Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web