google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank
Guest, register






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


Label: JavaScript event, HTML control, HTML JavaScript example code, 45

Free iPage Web Hosting for First Year NOW



If you're still looking for a reliable web host provider with affordable rates, why you don't take a little of time to try iPage, only with $1.89/month, included $500+ Free Extra Credits for the payment of 24 months ($45)?

Over 1,000,000+ existisng customers can not be wrong, definitely you're not, too! More important, when you register the web hosting at iPage through our link, we're going to be happy for resending a full refund to you. That's awesome! You should try iPage web hosting for FREE now! And contact us for anything you need to know about iPage.
Try iPage for FREE First Year NOW
  • Run a function 5 times with intervals of 20 seconds
  • 1.var count = 0;
    2.function myFunction() {
    3.    count++;
    4.    if(count > 5) clearInterval(timeout);
    5.    //do something
    6.}
    7.var timeout = setInterval(myFunction, 20000);
  • Check if an element exists
  • 1.if ($("#elementid").length) {
    2.    //it does!
    3.}
  • Cancel an ajax request
  • 01.var req = $.ajax({
    02.type:     "POST",
    03.url:     "someurl",
    04.data:     "id=1",
    05.success: function(){
    06.//something
    07.}
    08.});
    09.//Cancel the Ajax Request
    10.req.abort()
  • Check if cookies are enabled
  • 01.$(document).ready(function() {
    02.    var dt = new Date();
    03.    dt.setSeconds(dt.getSeconds() + 60);
    04.    document.cookie = "cookietest=1; expires=" + dt.toGMTString();
    05.    var cookiesEnabled = document.cookie.indexOf("cookietest=") != -1;
    06.    if(!cookiesEnabled){
    07.        //cookies are not enabled
    08.    }
    09.});
  • Toggle all checkboxes
  • 1.var tog = false; // or true if they are checked on load
    2.$('a').click(function() {
    3.    $("input[type=checkbox]").attr("checked",!tog);
    4.    tog = !tog;
    5.});
  • Get the index of an element
  • 1.$("ul > li").click(function () {
    2.    var index = $(this).prevAll().length;
    3.});
  • Validate date of birth
  • 01.$("#lda-form").submit(function(){
    02.    var day = $("#day").val();
    03.    var month = $("#month").val();
    04.    var year = $("#year").val();
    05.    var age = 18;
    06.    var mydate = new Date();
    07.    mydate.setFullYear(year, month-1, day);
    08. 
    09.    var currdate = new Date();
    10.    currdate.setFullYear(currdate.getFullYear() - age);
    11.    if ((currdate - mydate) < 0){
    12.        alert("Sorry, only persons over the age of " + age + " may enter this site");
    13.        return false;
    14.    }
    15.    return true;
    16.});
  • Test if an element is visible
  • 1.if($(element).is(":visible")) {
    2.    //The element is Visible
    3.}
  • Counting child elements
  • 01.<div id="foo">
    02.<div id="bar"></div>
    03.<div id="baz">
    04.<div id="biz">
    05.</div>
    06.<span><span>
    07.</div>
    08. 
    09.//jQuery code to count child elements
    10.$("#foo > div").length
  • Center an element on the screen
  • 01.jQuery.fn.center = function () {
    02.    this.css("position","absolute");
    03.    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    04.    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    05.    return this;
    06.}
    07. 
    08.//Use the above function as:
    09.$(element).center();
    iPhoneKer.com
    Save up to 630$ when buy new iPhone 15

    GateIO.gomymobi.com
    Free Airdrops to Claim, Share Up to $150,000 per Project

    https://tooly.win
    Open tool hub for free to use by any one for every one with hundreds of tools

    chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
    Talk to ChatGPT by your mother language

    Dall-E-OpenAI.com
    Generate creative images automatically with AI

    AIVideo-App.com
    Render creative video automatically with AI

    JavaScript by day


    Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web