开发者

Add styles to dynamically added elements with jQuery

heres the demo

http://lufi.realservers.info/d开发者_开发问答emos/add_forms_dynamically/

when i add another element (input boxes) i cannot remove the italicized-grayed labels inside unlike the first input boxes. Also, they only disappear if I click the first set of input boxes.

are there any other ways to add styles to dynamically added elements?


You can try the live() method to apply it to dynamically added element.


As well as using live for your events (which will apply to things not yet in the dom but will add events when they get added) you might also want to change your function that remove the text from the input because at the moment it will just remove all, which is probably not what you are wanting.

Instead of:

$('.inbox').css('color','black');
$('.inbox').css('font-style','normal');
$('.inbox').val('');

Try

$(this).css({'color': 'black', 'font-style': 'normal'}).val('');


you can also go for jQuery.delegate()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜