views:

35

answers:

1

On my portfolio page I have this setup:

<div id="portfolio">
        <ul id="sites">
          <li>
            <h3><a href="#">MotorSomethin</a></h3>
            <img src="http://dummyimage.com/265x100/000/fff" />
            <p>
              We tried going for a very dark but flashy look for this website. Hence the reason we used flash.
            </p>
          </li>
          <li>
            <h3><a href="#">MotorSomethin</a></h3>
            <img src="http://dummyimage.com/265x100/000/fff" />
            <p>
              We tried going for a very dark but flashy look for this website. Hence the reason we used flash.
            </p>
          </li>
          <li>
            <h3><a href="#">MotorSomethin</a></h3>
            <img src="http://dummyimage.com/265x100/000/fff" />
            <p>
              We tried going for a very dark but flashy look for this website. Hence the reason we used flash.
            </p>
          </li>
          <li>
            <h3><a href="#">MotorSomethin</a></h3>
            <img src="http://dummyimage.com/265x100/000/fff" />
            <p>
              We tried going for a very dark but flashy look for this website. Hence the reason we used flash.
            </p>
          </li>
          <li>
            <h3><a href="#">MotorSomethin</a></h3>
            <img src="http://dummyimage.com/265x100/000/fff" />
            <p>
              We tried going for a very dark but flashy look for this website. Hence the reason we used flash.
            </p>
          </li>
        </ul>
      </div>

So imagine a grid, 2 sites per line.

I want to use jQuery so that when I click the H3, the image, or the paragraph inside the LIE(which are all information about a certain site), it would fade out the entire UL, then grab info about that site from our database.

I think this requires AJAX but I don't have much experience with it. I'm also confused on how to use jQuery to write the new HTML after the information is grabbed.

+1  A: 

Not 100% sure what you want, but try something like this:

$("li").click(function() {
    $("#portfolio").fadeOut();

    // This performs an ajax-request to the "url/to/fetch". 
    // Then puts the result in the portfolio-div. finally 
    // it fades the results back in.
    $.get("url/to/fetch",{},function(data) {
        $("#portfolio").html(data);    
        $("#portfolio").fadeIn();
    });
});
dale
Sorry, that was cool but I'm grabbing the information from a database and not a web page.
NessDan
@NessDan: You cannot access your database from Javscript as JS works on the client side. You have to provide an URL from where you can fetch the information via Ajax. The page you call with this URL queries the database on the server side and generates the output .
Felix Kling
So I should have a page like project.php?id=1 and get it to check the database for that project? Makes sense now, thanks!
NessDan