JQuery的:帮助使用。每()和.append()将图片添加到HTML [英] JQuery: Help using .each() and .append() to add pictures to HTML

查看:1531
本文介绍了JQuery的:帮助使用。每()和.append()将图片添加到HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的错误是固定的,我无法弄清楚什么是错的。我需要在同一画面追加到HTML多(五)个div的。出于某种原因,我的code被追加相同的画面五次每个div。使其更清晰,每五个div的需要一张图片。眼下,所有五个各有五张图片。这里是jQuery的:

Simple bug that needs to be fixed and I can't figure out what's wrong. I need to append the same picture to multiple (five) divs in the HTML. For some reason, my code is appending the same picture five times to each div. Making it more clear, each of the five divs needs one picture. Right now, all five have five pictures each. Here is the JQUERY:

$(".faq").each(function(){
        $('.faq .letter-q').append('<img src="images/faq-q.png" alt="Question">');
});

这是它被插入:

<div class="letter-q"></div>

有整个身体与S $ P $垫出五。

There are five of those spread out across the body.

这也可能是小东西我失踪。任何帮助将是AP preciated!

It's probably something small I'm missing. Any help would be appreciated!

推荐答案

如果您要使用五.letter-Q div的第一个,然后选择他们先使。每次时运行该功能时它正在与这些div的:

If you want to work with the five .letter-q div's first then select them first so that ".each" time the function is run it is working with those div's:

$('.faq .letter-q').each(function(){
    //this wrapped in jQuery will give us the current .letter-q div
    $(this).append('<img src="images/faq-q.png" alt="Question">');
});

这篇关于JQuery的:帮助使用。每()和.append()将图片添加到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆