2

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"));

max pleaner
  • 26,189
  • 9
  • 66
  • 118

2 Answers2

3

console.dir logs html elements as objects. Explained here

Community
  • 1
  • 1
karaxuna
  • 26,752
  • 13
  • 82
  • 117
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