How to get specific value from jQuery object?

If I have an object like this:

var item = {
    id: '1',
    description: 'something'
}

then how do I extract one of these values? If i do

alert($(item.id));

then I just get the message "Object object". I looked at this post: Getting the base element from a jQuery object and tried to call

alert($(item).get(0)); 

But with the same result.

Also, in terms of terminology, which objects are similar to this, so next time I can be more specific?

+3
source share
4 answers
console.log(item.id)

$() returns a jQuery object.

0
source

Just use:

alert(item.id);

This: $(item.id)wraps item.id in a jQuery object, so you get an Object object

PS

, , , / ,

+5

Try the following:

alert ($ item.prop ('id'));

0
source

Using the normal procedure:

alert(item.id);

Using jQuery:

alert($(item).get(0).id);

Note

 $(item) -> return an array

 $(item).get(0) -> return object which is equal to (var item)

 $(item).get(0).id -> return id value
0
source

All Articles