在jquery中迭代并向每个元素添加attr
我的目标是为图片添加包装样式。样式由jquery ui添加,并放置在iframe中的html中:在jquery中迭代并向每个元素添加attr,jquery,jquery-ui,dom-manipulation,Jquery,Jquery Ui,Dom Manipulation,我的目标是为图片添加包装样式。样式由jquery ui添加,并放置在iframe中的html中: <div class="wrapper style:"xyz"> <img id="link1"> </div> <div class="wrapper style:"abc"> <img id="link1"> </div> <div class="wrapper style:"wer"> &
<div class="wrapper style:"xyz">
<img id="link1">
</div>
<div class="wrapper style:"abc">
<img id="link1">
</div>
<div class="wrapper style:"wer">
<img id="link1">
</div>
更正您的html
范例
<div class="wrapper" style="xyz">
<img id="link1">
</div>
<div class="wrapper" style="xyz">
<img id="link1">
</div>
$('div.wrapper').each(function(){
$(this).find('img').attr('style',$(this).attr('style'));
});