jQuery:获取内容/innerhtml onclick [英] jQuery: get content / innerhtml onclick
问题描述
如果您点击此页面上的单元格,则会加载该图像的较大版本.我正在尝试达到同样的效果.
If you click on a cell on this page, it loads the larger version of the image. I'm trying to achieve this same effect.
到目前为止,我得到了什么: http://jsfiddle.net/8mYW9/
What I have gotten so far: http://jsfiddle.net/8mYW9/
首先,我知道拥有"appear" <div>
是多余的-是否有一种很好的方法来代替使用$(this)
和appendTo();
?
First off I know having the "appear" <div>
is redundant - is there a good way to utilize $(this)
and appendTo();
instead?
最终,我的想法是获取被单击的div中包含的锚点的ID,并将其附加到单元格中.我该怎么办...?
Ultimately my idea is to grab the id of the anchor contained within the div that is clicked and to append it to the cell. What should I be doing...?
推荐答案
如果将appear
元素的ID属性更改为class,则可以执行以下操作:
If you change the ID attribute to class for the appear
elements you can do this:
$(document).ready(function() {
$('#appear').hide();
$('.links').click(function() {
var $this = $(this);//cache the $(this) selector since it will be used more than once
$this.children('.appear').html('item id: ' + $this.children('a').attr('id')).fadeToggle('slow');
});
});
演示: http://jsfiddle.net/8mYW9/7/
顺便说一句,HTML文档中不能有多个具有相同ID的元素.
BTW you can't have multiple elements with the same ID in a HTML document.
这篇关于jQuery:获取内容/innerhtml onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!