Jump to content

Append Method Not Working


son

Recommended Posts

I am working on this script in other post which is not resolved yet, but have a general Javascript question relating to this. When I try to use:function loadThumbs(){ for(var i=0; i < imageArray.length; i++) { thumbPath = '<a id="' + i + '" href="#" onclick="thumbClick(this.id);return false;"><img src="' + imageDir + '/thumb/' + imageArray + '" alt="Photography" /></a>'; $('#thumbnails').append(thumbPath); }}nothing is being appended to the div called 'thumbnails'. When I directly place:<div id="thumbnails"><script type="text/javascript"> for(var i=0; i < imageArray.length; i++) { thumbPath = '<a id="' + i + '" href="#" onclick="thumbClick(this.id);return false;"><img src="' + imageDir + '/thumb/' + imageArray + '" alt="desc" /></a>'; } </script></div>the thumbs are displayed. I do not get it. What is the difference? I call the loadThumbs function higher on as$(document).ready(function() { getTotal();});function getTotal(){ $.get(imageDir + "/thumb/files.php", function(data){ imageArray = data.split("|"); imageArray.pop(); imageTotal = imageArray.length; imageNo = 1; loadNavi(); // load thumbnails loadThumbs(); });} Where am I going wrong with this? Son

Link to comment
Share on other sites

I did this before, but there are no errors whatsoever. However, I tried nowdocument.write(imageArray.length); which shows 0anddocument.write(imageTotal); which brings up 'undefined'but I am not getting why the function would not be called. I have at top$(document).ready(function() { getTotal();});// FUNCTIONS BELOW// get image totalfunction getTotal(){ $.get(imageDir + "/thumb/files.php", function(data){ imageArray = data.split("|"); imageArray.pop(); imageTotal = imageArray.length; imageNo = 1; loadNavi(); // load thumbnails loadThumbs(); });}and thought $(document).ready(function() calls the function?Am I wrong with this assumption? Son

Link to comment
Share on other sites

as said, check the error console. Just google it for your browser if you don't know how to get to it. using document.write is an extremely bad practice. it will reload the page if you call it after the page has already loaded. Also, please use code tags when posting, if you have any formatting, it will be preserved and will make sight reading your code easier for everyone. in jquery, ready is a method that will be executed once the DOM has loaded. It is common practice to put any code inside so element references will be valid.http://api.jquery.com/ready/ once you have found your console, I would do heavy logging using console.log. log when a function gets called, what the data is, everything you can to help trace the execution of your script.

Link to comment
Share on other sites

When I said 'I did this before, but there are no errors whatsoever.' that was meant to say that I checked the errro console, but there are no errors, warning, messages whatsoever... I only used document.write to see what the values are, this should have not been in the 'real' life script, but I am open to suggestions how to be check what values are when I am debugging. What would you normally use? Also, what do you mean by logging everything? The error console does this automatically, doesn't it? Son

Link to comment
Share on other sites

console.log('ENTER function xyz');console.log('the value of x is => ' + x);console.log('the value of y is => ' + y);

It's up to you to figure out what is going on at all times over the course of your script. The console is just where errors and logging shows up. The logging is not automatic. edit: the old way is to use alert, but that's such a PITA...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...