![](/img/trans.png)
[英]Is there a direct way of appending text to a DOM element with jQuery?
[英]Jquery appending text to an element
目的是在下面的元素中附加一行文本。
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>";
這個代碼包含在一個循環中,所以每次創建一個新的錨點並給出一個遞增的ID(countwide),例如'anchor1''stock2'
我需要的是能夠將此變量作為此錨點內p元素的一部分附加到下方
image_price
我試過沒有進展。
$("#anchor1").append(image_price);
顯然我們需要上面一行中的id與循環一致增加。
謝謝。
嘗試:
$("#anchor" + countWide + " .popupDynamic").append(image_price);
說明:
我剛剛更新了選擇器,以便它使用#anchor + countWide
(這意味着錨加動態ID)的子.popupDynamic
並將價格附加到它。
您可以在selector
使用countWide
變量,方式如下:
$("#anchor"+countWide+" .popupDynamic").append(image_price);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.