I am doing one of the most simple and fundamental things with jQuery - taking a selection from the DOM and then printing it to the console. However, all I see in the console is [object, Object]. Here is the line in my js code which prints to console the selection console.log($(".map_id"));
Asked
Active
Viewed 665 times
2

max pleaner
- 26,189
- 9
- 66
- 118
-
which browser are you using? – karaxuna Mar 29 '14 at 22:56
-
firefox. im gonna try chrome now. – max pleaner Mar 29 '14 at 22:57
-
Try `console.dir` instead of `console.log` – karaxuna Mar 29 '14 at 22:58
-
I always use console.log([$(".map_id")]); to get around that – juvian Mar 29 '14 at 23:20
2 Answers
1
What king of HTML element is *$(".map_id")*?
If it's a input element you should use $(".map_id").val()
to get the input value.
Otherwise, if it's a div or p or span or any other HTML tag, you should use $(".map_id").html()
to get it contents.
Using just $(".map_id")
will return a jQuery object relative to *".map_id"* selection, not it value or content.

Elias Soares
- 9,884
- 4
- 29
- 59
-
Thank you for that suggestion about using .html(). This fixed the problem of seeing [object, Object] in the console, but I don't know how to parse the html that I see contained in that object. I tried console.dir() and it seems to be more promising. Thanks for your help though. – max pleaner Mar 29 '14 at 23:06