0

I want to retrieve the data inside a JSON object, but when I tried to alert it, or log it, I got [Object Object] or undefined. Say I'm getting the json object in a div with id = "page". This's what I did:

console.log($("#page").val()); //gives undefined
console.log($("#page").toString()); // gives [Object Object]

I'm getting the JSON object inside a div I introduced

<div id="page"></div>

From here I was trying to get the JSON object.

So how do I get the data inside this object?

5
  • $("#page")[0]? $("#page") is jQuery object, so toString() on it gives [Object object] Commented Nov 23, 2015 at 9:21
  • Please provide code of your page Commented Nov 23, 2015 at 9:23
  • You can see the data inside this object with : JSON.stringify($("#page")) Commented Nov 23, 2015 at 9:24
  • 1
    "JSON" does not mean what you think it means ... Commented Nov 23, 2015 at 9:25
  • @ R3tep: JSON.stringify isn't working. Commented Nov 23, 2015 at 9:40

1 Answer 1

2

To log the object of an DOM element simply:

console.log($("#page"));

To get the HTML content of it:

console.log($("#page").html());
Sign up to request clarification or add additional context in comments.

1 Comment

That gave undefined too.

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.