problem with $ (document) .on in jquery?

0

I have the following code:

$(document).on('focus', '.albaran', function () {
    console.log($(this).data('error'));
     if ($(this).data('error') == 1) {
       $(this).tooltip({ 'trigger': 'focus', 'title': 'El campo no puede estar vacio' });
     } else if ($(this).data('error') == 2) {
       $(this).tooltip({ 'trigger': 'focus', 'title': 'El campo no es numerico' });
     }
);

I would like to do this for other classes, Something like that

$(document).on('focus', '.albaran .Pais .Ruta', function ()

I do it that way but it does not work for me, is there a way to do it?

    
asked by Acd 15.06.2017 в 01:30
source

3 answers

1
$(document).on('focus', '.albaran, .Pais, .Ruta', function ()

That it serves you.

Greetings

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<p class="one">Prueba 1</p>
<p class="two">Prueba 2</p>
<p class="three">Prueba 3</p>
<p class="four">Prueba 4</p>
<script>
$(document).ready(function(){
  $(document).on('click','.one, .two, .three, .four',function(){
		alert($(this).text());
  });
});

</script>
    
answered by 15.06.2017 / 01:33
source
0

Separate the blank spaces in the comma%% expression%:

'.albaran .Pais .Ruta'

    
answered by 15.06.2017 в 02:31
0

I show you an example showing code according to jQuery 3.

  • Since jQuery 3 document.ready is deprecated , so it is recommended to use: $(function() { ...
  • You can hear $(".albaran, .ruta, .pais").click(function(){ without having to reference $document
  • If for any reason you want to show the contents of the three classes, you can hear a div identified by a id . If you are not interested in that way, you can delete this part of the code: $("div#test").on("click", function() ...

$(function() 
{ //Desde jQuery 3 document.ready es deprecated


    //Escuchar por clases
    $(".albaran, .ruta, .pais").click(function()
    {
        alert($(this).text());
    });

    //Escuchar por bloque
    $("div#test").on("click", function() 
    {
        alert($(this).text());
    });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">
    <p class="albaran">ALB123</p>
    <p class="pais">España</p>
    <p class="ruta">A4</p>
</div>
    
answered by 15.06.2017 в 02:40