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>
2
  • ...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, but cannot get it working... Commented Nov 23, 2012 at 0: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...? Commented Nov 23, 2012 at 0:19

1 Answer 1

3

You are missing the selector quotes '' and id hash

$('div#pitch').append("<div><img src='"+el[0]+"'>"+el[1]+"</div>");
Sign up to request clarification or add additional context in comments.

1 Comment

You solved it, thank you! I used 'div.pitch' though. What is the difference between dot and hash?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.