0

My JSON currently looks like this:

 {
  "overview" : {
    "title" : "Blog"
  },

  "item" : {
    "title" : "Hello World"
  }

 }

My jQuery looks like this:

<script type="text/javascript">

$(document).ready(function(){

      $.getJSON(url, function(obj) {

        $.each(obj, function(key, value){

          $('.image-slide-title').append(value.title);

        });

      });

});

</script>

All works perfectly fine except the HTML markup is showing:

<div class="image-slide-title">Blog Hello World</div>

I just want it to skip the overview key/value and just go right to the item key/value so at the end of the day it looks like:

 <div class="image-slide-title">Hello World</div>

1 Answer 1

3

You could then loop through the obj.item properties:

for (var prop in obj.item) {
   var value = obj.item[prop];
   $('.image-slide-title').append(value);
}
Sign up to request clarification or add additional context in comments.

2 Comments

You forgot to append .title onto the value
No, I didn't. It's not necessary. If you append that you no longer need to be looping through the properties because you are hardcoding the name of the property.

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.