Conflict when importing another Jquery in Wordpress

0

Hello, how are you? I have a problem that has already consumed me a lot of time, I'm trying to put a mask for time in an input field, the code is already ok and working the problem is when I import the js library inside the head of my header.php, because buga the rest of my whole site, tried some ways to import but nothing so far solved, tried the following ways:

var mask = function (val) {
    val = val.split(":");
    return (parseInt(val[0]) > 19)? "HZ:M0" : "H0:M0";
}

pattern = {
    onKeyPress: function(val, e, field, options) {
        field.mask(mask.apply({}, arguments), options);
    },
    translation: {
        'H': { pattern: /[0-2]/, optional: false },
        'Z': { pattern: /[0-3]/, optional: false },
        'M': { pattern: /[0-5]/, optional: false }
    },
    placeholder: 'hh:mm'
};

var $a = jQuery.noConflict()
$a(document).ready(function () {
  $a("#QuantidadeHoras").mask(mask, pattern);
});


 wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js');
    wp_enqueue_script( 'jquery' );

     wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.min.js');
    wp_enqueue_script( 'jquery' );
    
asked by anonymous 10.10.2017 / 20:37

1 answer

0

Just one question, why are you adding JS to header.php? Try to include it in footer.php (if you have one)

Try to do this:

does the following, overrides this: var $a = jQuery.noConflict() $a(document).ready(function () { $a("#QuantidadeHoras").mask(mask, pattern); }); so:

(function (document, $){ $('#QuantidadeHoras').mask(mask, pattern); }(document, jQuery)

OU:

jQuery(function(document).ready(){ $('#QuantidadeHoras').mask(mask, pattern); })

If I did not answer your question, I apologize.

    
10.10.2017 / 21:16