Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138249

How can I write an array values to different paragraphs in a html document using javascript/jquery?

$
0
0

Please, I want to print out the contents of an array to different blocks of paragraphs in HTML using javascript or jquery. I can console.log the problem but can write all individually to different paragraphs of the HTML document I need that to appear at.[my source code screenshot in js

// Latest
$(document).each(function() {
  var price = [];
  var oldprice = [];
  var discount;
  var i;
  $('.price').children('p').each(function() {
    price.push(this.innerHTML);
  });
  $('.old-price').children('p').each(function() {
    oldprice.push(this.innerHTML);
  });
  $(function(){
    for(i=0;i <= ((oldprice.length)&&(price.length));i++) {
      var mainprice = price[i].replace("₦",""); //new price
      mainprice = parseFloat(mainprice.replace(",",""));
      var oldmainprice = oldprice[i].replace("₦",""); //oldprice
      oldmainprice = parseFloat(oldmainprice.replace(",",""));

      var disc = oldmainprice - mainprice;
      var pectDisc = (disc / oldmainprice) * 100;
      pectDisc = parseInt(pectDisc);
      // console.log("-" + pectDisc + "%");
      var prices = [];
      var offs = [];

      prices.push(pectDisc);
      for(var x in prices) {
        if($(".off")) {
          $(".off").text("-" + prices[x] + "%");
          // console.log(prices[x]);
        }
      }
    };//end of for loop
  });
});
<div class="asses-product"><div class="pd"><div class="img"><img src="img/Products/laptop.png" alt="product-image"></div><div class="product-description"><div class="product-name"><h4><a href="#">Hp Laptop Envy 14</a></h4></div><div class="price"><p>₦ 256,000</p></div><div class="old-price"><p>₦ 300,000</p></div><div class="off"></div></div></div><div class="pd"><div class="img"><img src="img/Products/printer.png" alt="product-image"></div><div class="product-description"><div class="product-name"><h4><a href="#">Hp printer series 10</a></h4></div><div class="price"><p>₦ 12,500</p></div><div class="old-price"><p>₦ 18,000</p></div><div class="off"></div></div></div></div>

]1


Viewing all articles
Browse latest Browse all 138249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>