Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2012
    Location
    Nebraska, USA
    Posts
    132
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Post How do I print an Array of Objects?

    Hello!

    I have a pretty straight forward question dealing with JQuery/Javascript (I'm pretty new to both, so the syntax is still escaping me). I have a javascript file that holds an array of objects inside of it (addresses to be exact) and I then need to take that array and call it to print into the Title attribute of a <li> after the list has been populated.

    Below is the Javascript arrray:
    Code:
    var banner_data = [ "address1","address2","address3","address4"];
    var obj = { one:"address1", two:"address2", three:"address3", four:"address4" }
    And this is how it is being called in the HTML:
    Code:
    $('ul>li').each(function(){
          var $this = $(this); // current list item
          var idx = $this.index();
          var thisAddress = banner_data[idx]; 
    	  $this.attr('title', thisAddress.append[4])
    });

    any thoughts? I have jQuery 1.7.1 installed, a fully valid html/css and a proper doctype (just to cover our bases haha)
    Last edited by dylanbaumannn; 03-08-2012 at 03:44 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2012
    Location
    Nebraska, USA
    Posts
    132
    Thanks
    8
    Thanked 19 Times in 19 Posts
    also, It does target the correct title in the correct lists. When I change
    Code:
     $this.attr('title', thisAddress.append[4])
    to
    Code:
     $this.attr('title', 'test')
    it will change the title attribute to 'test' perfectly. I'm just having trouble with the append/print syntax

  • #3
    Regular Coder
    Join Date
    Feb 2012
    Location
    Nebraska, USA
    Posts
    132
    Thanks
    8
    Thanked 19 Times in 19 Posts
    changing
    Code:
      $this.attr('title', thisAddress.append[4])
    to
    Code:
      $this.attr('title', thisAddress)
    fixed it


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •