javascript - Issue On Using Text() in a loop -


can please take @ demo , let me know why getting last item in .result

for (i = 0; < 5; i++) {     $('.result').text('hello' + [i]);  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="result"></div>

you can append source code within new element.

for (i = 0; < 5; i++) {     $('.result').append( $('<p>').text('<p>' + 'hello' + [i] + '</p>') );  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="result"></div>


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -