0

I am using a plugin called h5validate. I have found the only way to initiate this plugin is by clicking out of (bluring) the field i want to validate, so my logic is to setup a function which does this for me when i click (as it happens) a next button; I have tried calling the validate function directly but it doesn't work.

Anyway my question is:

1. This function hangs the browser for ~3seconds, why?

$(document).on('click', '.tab', function () {
$this = $(this);
    if( $this.is('#tab1') )     { $('.tab-content-first .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab2') )     { $('.tab-content-1 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab3') )     { $('.tab-content-2 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab4') )     { $('.tab-content-3 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab5') )     { $('.tab-content-4 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab6') )     { $('.tab-content-5 .row .cell input:not(#ImageLocation)').blur(); }
});

Edit: I have cashed $('this'); as an object as suggested.

I've decided it's probably bubbling up, the docs recommend i stoppropagation(), but that doesn't work, i'm using delegation as i'm calling this through ajax could that be why stoppropagation() doesn't work?

Edward
  • 1,806
  • 5
  • 26
  • 36

1 Answers1

0

First: $(this) should be cached. The rest of $() can be also cached, and before function.

Second: use strategy pattern

Sorprop
  • 153
  • 1
  • 8