1

It returns /dev/null, why? I try to populate new divs with an image and some text.

<html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<body>
    <div id='pitch'></div>
</body>
<script>
var v= new Array();
v[0] = new Array('h.png','Happy1!');
v[1] = new Array('hh.png','Happyy2!');
v[2] = new Array('hhh.png','Happyyy3!');

$(v).each(function(index,el){
        $(div.pitch).append("<div><img src='"+el[0]+"'>"+el[1]+"</div>");
}); 
</script>
hhh
  • 50,788
  • 62
  • 179
  • 282
  • ...I doubt the part `$(v)` to be nothing, how can I check it? A bit stupid question because I could ask it also as `How can I loop over an array in jQuery?`, the answer is each, more [here](http://stackoverflow.com/questions/3010840/loop-through-array-in-javascript), but cannot get it working... – hhh Nov 23 '12 at 00:16
  • Your second script block should be inside the body of the document. If it's not in the head or body it's not valid. You're also using div.pitch which refers to an object called div with a property called pitch (which isn't defined). Did you mean to select by id i.e. `$("#pitch").append...`? – Sean Powell Nov 23 '12 at 00:19

1 Answers1

3

You are missing the selector quotes '' and id hash

$('div#pitch').append("<div><img src='"+el[0]+"'>"+el[1]+"</div>");
Bruno Sousa
  • 480
  • 3
  • 12
  • You solved it, thank you! I used `'div.pitch'` though. What is the difference between dot and hash? – hhh Nov 23 '12 at 00:23