简体   繁体   中英

how would i go about adding some paragraphs on the go and show the result to the document with paragraph tags

I need to add 3 paragraphs tags here straight from the script that prints The same thing that logs on the console

<script >

var array= [1,2,4];
  $.each(array,function (index,value)   {
     console.log(index + ": "+value)
    });
</script>

Use this Demo Here

 <script>
    var array= [1,2,4];
  $.each(array,function (index,value)   {
       $('<p>').appendTo('body').html(index + ": "+value);
  })
    </script>

May be it will help you.

 var array= [1,2,4]; $.each(array,function(index,value){ $('<p />').appendTo('#apd').html(index + ": "+value); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id='apd'></div> 

Try this..

<body>
<div id="data"></div>
</body>
<script>
var test="";
var array= [1,2,4];
 for (i = 0; i < array.length; i++) { 
      test += '<p>'+i+ ':'+array[i]+'</p>';
    }

    document.getElementById("data").innerHTML = test;
</script>

Output:

0:1

1:2

2:4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM