How to change attribute of .html file just loaded with jquery

<html >
<head>
<title>main files</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<div id="kk">
</div>
<script>
    $("#kk").load("template.html");
    var new_id="234";
    $(#tkk).attr({
                   id : this.id + '_' + new_id,
                   name: this.name + '_' + new_id

                 });            

</script>
</body>
</html>

      

<--------------------------------------------- ---- ----------------->

template.html

<h2>Greetings</h2>
<div id="tkk" class="container">
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

      

here i want to change tkk id after upload to main.html file but its not working

+3


source to share


1 answer


inside a function load

, this way your desired changes will happen after a successful AJAX load, not at the same time.



$("#kk").load("template.html", function(){
    var new_id="234";
    $("#tkk").attr({
           id : this.id + '_' + new_id,
           name: this.name + '_' + new_id   
    });  
});

      

+3


source







All Articles