4
<div id="w01">
<img src=g_bur/01.jpg alt='img'>
<img src=g_bur/02.jpg alt='img'>
<img src=g_bur/03.jpg alt='img'>
</div>

I need an array of elements made from this images

js

var arr = [];
$("#w01 > img").each(function(){
    arr.push($(this));
}
alert (arr) //error

Error: Uncaught SyntaxError: Unexpected identifier

2 Answers 2

3

Use toArray():

var arr = $("#w01 > img").toArray();

... or alter your original code like so:

var arr = [];
$("#w01 > img").each(function(){
    arr.push(this); // this instead of $(this) so you only get the <img>
}); // you were missing a closing paren
alert(arr);
Sign up to request clarification or add additional context in comments.

Comments

1

You forgot to put ')'

Here:

$("#w01 > img").each(function(){
    arr.push($(this));
}); //<<<<

Comments

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.