我是 jquery 新手,我正在做一个 slider 。
我有:
<ul>
<li> <img src="image.jpg"><p>description of the current image</p></li>
<li> <img src="image.jpg"><p>description of the current image</p></li>
<li> <img src="image.jpg"><p>description of the current image</p></li>
<li> <img src="image.jpg"><p>description of the current image</p></li>
</ul>
我需要做的是当我点击特定的 <li>
时元素,它将及其内容显示在灯箱中。
<div id="lightbox">Here is clicked li and its content</div>
我真的不知道从哪里开始。
我如何告诉 jQuery 采取 li
并放入div
?
最佳答案
您可以执行以下操作:
$(document).ready(function() {
$('li').on('click', function() {
$('#lightbox').html($(this).html());
});
});
关于javascript - 如何取出一个li并将其放入特定的DIV中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30673210/