How do I modify the attributes of an input, which has been created by means of an ajax response?

0

I am trying to modify the attributes of an input that I generate dynamically and that I show on the page through ajax.

function traigo_form(){
    $.ajax({
        data:{enviado: true}   
        type: "POST",
        url: "localhost/miproyecto/traer_form.php",
        success: function(data){
            $('#formulario').html(data);                
        }
    });
    $("#valor").attr("type","hidden");
}
<button onclick="traigo_form()" id="boton" value="traer"></button>
<div id='formulario'>

</div>
<?php
if($_POST['enviado']){
    $formulario="<form>
    <input id=\"nombre\" type=\"text\">
    <input type=\"text\" id=\"valor\">
    </form>";
    echo $formulario;
}
    
asked by Juan Sebastian Rodriguez 05.12.2016 в 23:07
source

1 answer

0

  function traigo_form()
    {
        $.ajax(
        {
            data:{enviado: true}   
            type: "POST",
            url: "localhost/miproyecto/traer_form.php",
            success: function (data)
            {
                $('#formulario').html(data); 
                $("#valor").attr("type","hidden");               
            }
        });

  }

Since Ajax's grace is its asynchronous nature, the change of the attribute should be done in the function success

    
answered by 06.12.2016 в 06:02