javascript - How to get div value when id of div is created in for loop -


please tell me solution of problem. creating 5 dynamic divs , ids using loop. want the loop counter value , each of created div's html in format "counter: html" 1:123. right getting loop counter value.

<html> <div id="feed"></div>  </html> <script>   (var = 1; <= 5; i++) {     $('#feed').append('<div id="news' + + '" value='       123 '/>');        var abc = $("#news" + i).attr("value");     console.log(abc);   } </script> 

thanks in advance.

try this.

$(document).ready(function() {    (var = 1; <= 5; i++) {      $('#feed').append('<div id="news' + + '" value="123"></div>');        //and want value of dynamic created div using code getting loop counter value. please me answer.        var abc = $("#news" + i).attr('value');      console.log(abc + " : " + i);    }  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <html>  <div id="feed"></div>    </html>


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -