How to use jquery variable value

Asked

Viewed 253 times

1

I am having trouble using the value that is inside my variable when I use it jquery

var id_pais =  $('#endUF option[value=id_pais]').text();
        $('#endUF option[value=id_pais]').remove();
        $('#endPAIS option[value=id_pais]').prop('selected', true);

In case I take the value of my system and put it in a js variable. But then I can’t reuse it in jquery. I read about it and saw that when I use value in jquery, like the one used above, jquery sees it as a string and does not take the value of the variable.

1 answer

1


The variable was missing. Try the following:

var id_pais =  $('#endUF option[value=' + id_pais + ']').text();
        $('#endUF option[value=' + id_pais + ']').remove();
        $('#endPAIS option[value=' + id_pais + ']').prop('selected', true);
  • 1

    Thank you. That’s right, but I had trouble using Strings in variables. I had better results when using numbers.

  • All right. I’m glad you were able to solve. ;)

Browser other questions tagged

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