Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p> I've refactored your code as follows:</p> <pre><code>function GetGenres(){ $.post('tagcloud.php', function(data){ //create list for Genre tags var $ul = $('&lt;ul&gt;').attr('id', 'tagList'); var Count = []; var GenreName = []; $(data).find('row').each(function(i){ GenreName[i] = $(this).find('GenreName').text(); Count[i] = $(this).find('Count').text(); var $li = $('&lt;li&gt;'); if( (Count[i] / 10) &lt; 1 ) { var fontSize = (Count[i] / 10 + 1) + 'em'; } else if( (Count[i] / 10) &gt; 2 ) { var fontSize = '2em'; } else { var fontSize = (Count[i] / 10) + 'em'; } var $tagCloudLink = $('&lt;a href="javascript:void(0)"&gt;') .text(GenreName[i]) .css('font-size', fontSize) .bind('click', function(){ Genre_Clicked( GenreName[i] ) }); // add to list item $tagCloudLink.appendTo($li); // add to main list $li.appendTo($ul); }); // add to container div $ul.appendTo('#tagCloud'); }, 'xml'); } $(document).ready(function(){ GetGenres(); }); </code></pre> <p><strong>Question:</strong></p> <ul> <li><strike>Where is <code>val.freq</code> coming from? I've included it above, but obviously it won't work as is.</strike> OP noted that <code>val.freq</code> should be <code>Count[i]</code>.</li> </ul> <p><strong>Some pointers:</strong></p> <ul> <li>When making changes to the DOM, you want to limit the number of times you write to it. So it's generally preferable to create all your dynamic elements in memory, then write to the DOM in one shot.</li> <li>If you plan on using <code>Genre[]</code> or <code>Count[]</code> after the initial data processing, they'll only be available within the scope of <code>$.post()</code> due to the asynchronous call. I would suggest passing them to another function or using them inside <code>$.post()</code>.</li> </ul> <p><strong>EDIT:</strong></p> <ul> <li>Guess it would help if I changed <code>Genre[i]</code> to <code>GenreName[i]</code>.</li> <li>I've tested the main data processing loop above by ripping it out and replacing <code>data</code> with a simple array of the form <code>[ [genre0,count0], ... ]</code>. It works as expected so hopefully you can adapt it further if this still doesn't work for you.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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