views:

57

answers:

2

Say I have a loop of objects (style.cover.pic) in a DIV .style_image

<% @styles.each do |style| %>

<div class="style_image"> <%=link_to (image_tag style.cover.pic.url(:small)), style %></div>

With the use of JQuery On a click event I want to load (this.href) in to the div .style_image which was click not all of the .style_image DIV's.

this is what I have done so fare:

$(function() {

$(".style_image a").live('click', function(event) { 


    $(".style_image a").load(this.href + " #show_style");

    $.get(this.href, null, null, "script");
    return false;       

});
});

Can this be done? and yes how???

Regards

Dan

A: 

Try using:

$(this).attr('href');

instead of:

this.href
Sarfraz
+1  A: 

Do it like this:

$(function() {
  $(".style_image a").live('click', function(event) { 
    $(this).closest(".style_image").load(this.href + " #show_style");
    return false;       
  });
});

On click, this looks from the link was was clicked to it's .style_image parent, then loads the content there.

Nick Craver
This worked perfectly!!!
MrThomas
Is it possible to cancel the load apon a new click event like a if statement?$(function() { if('.show_style').unload(this.href); $(".style_image a").live('click', function(event) { $(this).closest(".style_image").load(this.href + " #show_style"); return false; });});
MrThomas
@MrThomas - Not using `.load()`, but you could with the `$.ajax({})` expanded form which returns the XMLHttpRequest object, see here for details: http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery
Nick Craver
Cheers Nick, but I have no Idea how to implement gonna check out, the JQuery doc's.
MrThomas
@MrThomas - Here's what the ajax expanded form would look like, that help? http://jsfiddle.net/wu6z7/
Nick Craver