javascript - How to get div value when id of div is created in for loop -
please tell me solution of problem. creating 5 dynamic div
s , id
s 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>