[英]Jquery appending text to an element
The aim is to append a line of text into the element below. 目的是在下面的元素中附加一行文本。
anchorElement = "<a id='anchor" + countWide + "' class=\"boxOPT oneplustwo\" alt=\'"+ image_website +"' style=\"cursor:pointer;width:"+ itemWidth + "px"+";height:"+anchorHeight+";position:absolute;left:"+ locationLeft + "px"+";top:0.3%;\" ><p class=\"popupDynamic\"> " + popupImageTitles[i] + "</p>";
this code is contained within a loop so each time a new anchor is created and given an incremented ID (countwide) for for example 'anchor1' 'anchor2' 这个代码包含在一个循环中,所以每次创建一个新的锚点并给出一个递增的ID(countwide),例如'anchor1''stock2'
What I need is to be able to append this variable below as part of the p element inside this anchor 我需要的是能够将此变量作为此锚点内p元素的一部分附加到下方
image_price
I have tried this with no progress. 我试过没有进展。
$("#anchor1").append(image_price);
obviously we need the id in the line above to increment in line with the loop. 显然我们需要上面一行中的id与循环一致增加。
Thanks. 谢谢。
Try: 尝试:
$("#anchor" + countWide + " .popupDynamic").append(image_price);
Explanation: 说明:
I have just updated the selector so that it would pick up the child of the #anchor + countWide
(this means anchor plus the dynamic ID) with the class of .popupDynamic
and append the price to it. 我刚刚更新了选择器,以便它使用
#anchor + countWide
(这意味着锚加动态ID)的子.popupDynamic
并将价格附加到它。
您可以在selector
使用countWide
变量,方式如下:
$("#anchor"+countWide+" .popupDynamic").append(image_price);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.