简体   繁体   中英

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'

What I need is to be able to append this variable below as part of the p element inside this anchor

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.

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.

您可以在selector使用countWide变量,方式如下:

$("#anchor"+countWide+" .popupDynamic").append(image_price);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM