Js does not work as expected on my website even it works on codepen

O.k

I tried to design an js algorithm that overrites to existing HTML on my product detail page. This is required after XML integration to my website i want to visualize this specs as table but after XML integration it only allows to store on my website as paragraph tags of HTML.

So;

Here is my code that works exactly well on codepen but not on my wordpress website.

JS

var a,b,c,d,e,f;
var bazes = document.getElementById("prd-desc").getElementsByTagName("div")[0].getElementsByTagName("p") ;
var bazes_t = document.getElementById("prd-desc").getElementsByTagName("div")[0];

a = bazes[0].innerText;
b = bazes[1].innerText;
c = bazes[2].innerText;
d = bazes[3].innerText;
e = bazes[4].innerText;
f = bazes[6].innerText;

//console.log(c);

bazes_t.innerHTML = '<div class ="outer-box"> <table id="urun_inf"> <tr> <td class="col1-head"> Kod </td> <td class="col2-desc">a</td> </tr> <tr> <td class="col1-head"> Ebat </td> <td class="col2-desc"> Açıklama2 </td> </tr> <tr> <td class="col1-head"> Reklam Alanı</td> <td class="col2-desc"> Açıklama3 </td> </tr> <tr> <td class="col1-head"> Renk </td> <td class="col2-desc"> Açıklama4 </td> </tr> <tr> <td class="col1-head"> Merkez Stok </td> <td class="col2-desc"> Açıklama5 </td> </tr> <tr> <td class="col1-head"> Toplam Stok </td> <td class="col2-desc"> Açıklama6 </td> </tr> </table> </div><style> .outer-box{ border : 2px solid; border-style : groove; width : %100; height : auto;}.col1-head,.col2-head{ font-weight : bold; color : blue;}.col1-desc::before,.col2-desc::before{ content : ":";}</style>';

console.log(bazes_t.getElementsByTagName("td")[1].innerText);

bazes_t.getElementsByTagName("td")[1].innerText = a;
bazes_t.getElementsByTagName("td")[3].innerText = b;
bazes_t.getElementsByTagName("td")[5].innerText = c;
bazes_t.getElementsByTagName("td")[7].innerText = d;
bazes_t.getElementsByTagName("td")[9].innerText = e;
bazes_t.getElementsByTagName("td")[11].innerText =f;
<div data-id="6f6ba5e" class="elementor-element elementor-element-6f6ba5e elementor-widget elementor-widget-product-description" id="prd-desc" data-element_type="product-description.default">
				<div class="elementor-widget-container">
			<p>Lacivert</p>
<p>Bisiklet Yaka Lacivert Tişört</p>
<p>M Beden</p>
<p>1458</p>
<p>1458</p>
<p>&nbsp;</p>
<p>* %100 Pamuklu * 30/1 Süprem Kumaş * İstenilen renk ve bedenlerde dikim yapılır * Yandan Dikişli * 145 gr.</p>
		</div>
				</div>

So this code looks great on codepen or here. I implement this code on my OceanWP wordpress website by Elementor to "Single Product Page of Woocommerce" I can re-design this page with a plugin. ( It allows me to add an elementor custom HTML to this page and i implement this code there within 'script /script' tags)

Every product has unique specs so that this JS must be take data for each product page and display it as table like the code above.

Many thanks in advance,

C.

Ashfaque Ali Solangi

Not sure what you want to do with this code, just change your javascript code (just need to add window.onload and it should work.

window.onload = function(){
  var a,b,c,d,e,f;
  var bazes = document.getElementById("prd-desc").getElementsByTagName("div")[0].getElementsByTagName("p");
  var bazes_t = document.getElementById("prd-desc").getElementsByTagName("div")[0];

  a = bazes[0].innerText;
  b = bazes[1].innerText;
  c = bazes[2].innerText;
  d = bazes[3].innerText;
  e = bazes[4].innerText;
  f = bazes[6].innerText;

  //console.log(c);

  bazes_t.innerHTML = '<div class ="outer-box"> <table id="urun_inf"> <tr> <td class="col1-head"> Kod </td> <td class="col2-desc">a</td> </tr> <tr> <td class="col1-head"> Ebat </td> <td class="col2-desc"> Açıklama2 </td> </tr> <tr> <td class="col1-head"> Reklam Alanı</td> <td class="col2-desc"> Açıklama3 </td> </tr> <tr> <td class="col1-head"> Renk </td> <td class="col2-desc"> Açıklama4 </td> </tr> <tr> <td class="col1-head"> Merkez Stok </td> <td class="col2-desc"> Açıklama5 </td> </tr> <tr> <td class="col1-head"> Toplam Stok </td> <td class="col2-desc"> Açıklama6 </td> </tr> </table> </div><style> .outer-box{ border : 2px solid; border-style : groove; width : %100; height : auto;}.col1-head,.col2-head{ font-weight : bold; color : blue;}.col1-desc::before,.col2-desc::before{ content : ":";}</style>';

  console.log(bazes_t.getElementsByTagName("td")[1].innerText);

  bazes_t.getElementsByTagName("td")[1].innerText = a;
  bazes_t.getElementsByTagName("td")[3].innerText = b;
  bazes_t.getElementsByTagName("td")[5].innerText = c;
  bazes_t.getElementsByTagName("td")[7].innerText = d;
  bazes_t.getElementsByTagName("td")[9].innerText = e;
  bazes_t.getElementsByTagName("td")[11].innerText =f;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does my CSS not work as expected in Safari but it works fine on Chrome

From Dev

JavaScript doesn't work in my browser but works in CodePen

From Dev

Code works on codepen but not on my site

From Dev

Code works on JS fiddle but not on my website

From Dev

Code works on JS fiddle but not on my website

From Dev

Why does my program not work as expected?

From Dev

why does my hamcrest "contains" not work as expected?

From Dev

My collision list does not work as expected

From Dev

why does my hamcrest "contains" not work as expected?

From Dev

Link doesn't work in JSFiddle but works in CodePen

From Dev

my Polymer website does not work on firefox

From Dev

build apk does't work, but debug apk works as expected

From Dev

Removing a <div> section with JS does not work as expected

From Dev

Meteor JS Jade template does not work as expected

From Dev

JQuery/JS script not running in html (works in Codepen)

From Dev

My static instance function of my class does not work as I expected

From Dev

Why does my CSS selector does not work as expected?

From Dev

CSS Animation does not work on CodePen or anywhere but on JSFiddle

From Dev

JS and Bootstrap work in Codepen but not when opened locally

From Dev

My vba code does not seem to work, even though there are no errors

From Dev

Divs not aligning properly on website (work fine in CodePen though)

From Dev

Although my ISR handler works perfectly, IRQ handler does not work

From Dev

My program not work as expected

From Dev

My program not work as expected

From Dev

Angular material gridlist with dynamic text works in codepen but not on my server

From Dev

why my angular js code does not work

From Dev

@VisibleForTesting does not work as expected

From Dev

Scanf does not work as expected

From Java

ConcurrentHashMap does not work as expected

Related Related

  1. 1

    Why does my CSS not work as expected in Safari but it works fine on Chrome

  2. 2

    JavaScript doesn't work in my browser but works in CodePen

  3. 3

    Code works on codepen but not on my site

  4. 4

    Code works on JS fiddle but not on my website

  5. 5

    Code works on JS fiddle but not on my website

  6. 6

    Why does my program not work as expected?

  7. 7

    why does my hamcrest "contains" not work as expected?

  8. 8

    My collision list does not work as expected

  9. 9

    why does my hamcrest "contains" not work as expected?

  10. 10

    Link doesn't work in JSFiddle but works in CodePen

  11. 11

    my Polymer website does not work on firefox

  12. 12

    build apk does't work, but debug apk works as expected

  13. 13

    Removing a <div> section with JS does not work as expected

  14. 14

    Meteor JS Jade template does not work as expected

  15. 15

    JQuery/JS script not running in html (works in Codepen)

  16. 16

    My static instance function of my class does not work as I expected

  17. 17

    Why does my CSS selector does not work as expected?

  18. 18

    CSS Animation does not work on CodePen or anywhere but on JSFiddle

  19. 19

    JS and Bootstrap work in Codepen but not when opened locally

  20. 20

    My vba code does not seem to work, even though there are no errors

  21. 21

    Divs not aligning properly on website (work fine in CodePen though)

  22. 22

    Although my ISR handler works perfectly, IRQ handler does not work

  23. 23

    My program not work as expected

  24. 24

    My program not work as expected

  25. 25

    Angular material gridlist with dynamic text works in codepen but not on my server

  26. 26

    why my angular js code does not work

  27. 27

    @VisibleForTesting does not work as expected

  28. 28

    Scanf does not work as expected

  29. 29

    ConcurrentHashMap does not work as expected

HotTag

Archive