Hi eid,

I've taken a look at what you are trying to do and I think there are
two aspects that need to be 'corrected'.

1.) In the JSON, there is no need for an array of items  - remove the
[ & ] after 'items'.  items is then an object with elements called
'lanceOfMitraDivinity', 'wrathOfMitraDivinity', etc.  Much easier to
handle.

2.) To setup the buttons you would be better like this (not the only
way to do it, but this works!):
    $.getJSON('featsCalculator/priestofmitra.js', function(data)
    {
      $('.featButton').click(function()
      {
      var t = $(this).attr('id');
        if(data.items[t])
        {
          $('#state').html(data.items[t].description.base);
        }
      });
    });

You can use the items part of the json like an array, even though it
is an object - because all objects can be accessed either via the dot
operator (.) or using square brackets ([]).

Here is some tested code that works with the modified json you
provided.  Just cut and paste (modify any filenames and paths) and try
it.

----- start of code

<script type="text/javascript" src="js/jquery.js"></script>
<script>
  $(document).ready(function()
  {
    $.getJSON('featsCalculator/priestofmitra.js', function(data)
    {
      $('.featButton').click(function()
      {
      var t = $(this).attr('id');
        if(data.items[t])
        {
          $('#state').html(data.items[t].description.base);
        }
      });
    });
  });
</script>
<div id='state'></div>
<div class='featButton' id='lanceOfMitraDivinity'>Lanc</div>
<div class='featButton' id='piercingLanceDivinity'>Pier</div>
<div class='featButton' id='condemnationDivinity'>Cond</div>

----- end of code

Hope that helps a bit.

Cheers,
Dave

On May 1, 5:03 pm, eid <[EMAIL PROTECTED]> wrote:
> Okay I tried to do what you said.
>
> This is my JSON file:http://pastebin.com/m616d0550
>
> and this is my js file:
> $(document).ready(function() {
>         $.getJSON('featsCalculator/priestofmitra.js', function(data) {
>                 $('.featButton').hover(function() {
>                         if(data.items.jsname == $(this).attr('id')) {
>                                 alert(data.items.jsname);
>                         }
>                 });
>         });
>
> });
>
> Nothing happens when I hover a .featButton. What's wrong?

Reply via email to