Note that there are some explanatory texts on larger screens.

plurals
  1. POappend to div one time
    text
    copied!<p>I am revisiting this code I made a year ago with the help of another person. Unfortunately I don't have contact with them anymore to get more help. Basically It dynamically adds classs to the <code>tb</code> and <code>b</code> nodes of a document coming from <code>namesToChange</code>. Now what I am trying to do is append some text to the <code>div</code> with class <code>dtxt</code> node but still use this code below. I am using the code <code>$('td.pn_adm_jeff').children('div.dtxt').append('zzz');</code> and it works but it constantly appends more than once as seen in the photo below. How do I go about making it add once and stop?</p> <p><strong>Photo</strong> <a href="http://img6.imageshack.us/img6/5392/7c23ddb145954aefadb1b9f.png" rel="nofollow">http://img6.imageshack.us/img6/5392/7c23ddb145954aefadb1b9f.png</a></p> <p><strong>Code</strong></p> <pre><code> function customizefields(a) { $('td b').each(function () { name = $(this).text(); if (name.indexOf(" ") != -1) { name = name.substring(0, name.indexOf(" ")) } if (a[name]) { this.className = a[name].class; this.parentNode.className = a[name].img } }) $('td.pn_adm_jeff').children('div.dtxt').append('zzz'); } var namesToChange = { 'Jeff' :{'class':'pn_adm','img':'pn_adm_jeff'} }; setInterval(function () { customizefields(namesToChange) }, 1000); </code></pre> <p><strong>Update</strong></p> <pre><code>var needsUpdate = true; function customizefields(a) { $('td b').each(function () { name = $(this).text(); if (name.indexOf(" ") != -1) { name = name.substring(0, name.indexOf(" ")); } if (a[name]) { this.className = a[name].class; this.parentNode.className = a[name].img; } }); if (needsUpdate) { $('td.pn_adm_jeff').children('div.dtxt').append('testing'); needsUpdate = false; } } var namesToChange = { 'jeff' :{'class':'pn_adm','img':'pn_adm_jeff'}; }; setTimeout(function () { customizefields(namesToChange); }, 1000); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload