Rails with JQuery DIV manipulation
Say I have a loop of objects (style.cover.pic) in a DIV .style_image
<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开发者_StackOverflow中文版.
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
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.
Try using:
$(this).attr('href');
instead of:
this.href
精彩评论