code block only works with F5

Asked

Viewed 28 times

0

someone would tell me why this block of code only works after refreshing the page?

var count = 0;

$( document ).ready(function() {

//  alert("testando bloco");
  $("#select_n").attr('id', 'select_' + count);

  $("#add").click(function(){
    count ++;

    // desnecessario
    $("#select_n").attr('id', 'select_' + count);

    //$("#filtro_subdisciplinas_select").attr('id', 'subdisciplinas_select_' + count);
    $("#subdisciplina_select_n").attr('id', 'subdisciplina_select_' + count);
    //$("#carro_div_n").attr('id', 'carro_div_' + carro_temp);

  });
});

1 answer

1

Are you talking about $("#select_n") and changing your id to select_' + count. Then inside the click tries to refer to new id. $("#select_"+(count-1)).

var count = 0;

$( document ).ready(function() {
   //  alert("testando bloco");
   $("#select_n").attr('id', 'select_' + count);

   $("#add").click(function(){
        count ++;

        // desnecessario
        $("#select_"+(count-1)).attr('id', 'select_' + count);

        //$("#filtro_subdisciplinas_select").attr('id', 'subdisciplinas_select_' + count);
        $("#subdisciplina_select_"+(count-1)).attr('id', 'subdisciplina_select_' + count);
        //$("#carro_div_n").attr('id', 'carro_div_' + carro_temp);
    });
 });
  • 1

    is that the #add button generates another field with id $("#select_n"), it does not appear there because it does so through a framework called Gem in ruby on Rails

  • Try to show more information in your question @Erasmosantos. I do not use ruby on Rails any further than I said no error in this piece of code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.