Wrapping up Elements with JQuery
I do have a element and its content some where on the page :
<div style="padding-bottom:9px; font-size:13px;line-height:25px;">
Fine quality, full grain pebble leather
<br>
<div style="line-height: normal; margin-bottom: 6px; ">
Sophisticated black with detailed accent lining
</div>
Tailored satin ribbon release pull-strap
<br>
Slim back pocket for an ID card or money
<br>
Ultra slim design
<br>
Shock-absorbent construction
<br>
Additional screen padding
<br>
Light and rigid protective layer
<br>
Soft velvet lining with light protective layer
<br>
<div style="line-height: normal; margin-bottom: 6px; ">
Thinner and more streamlined than the Eléga Pouch
</div>
Sena high-quality handmade craftsmanship<br>
</div>
What I want to is convert the content above to below with jQuery (I tried different ways but after all I kinda lost)
<div style="padding-bottom:9px; font-size:13px;line-height:25px;">
<div style="line-height: normal; margin-bottom: 6px;">
Fine quality, full grain pebble leather
</div>
<br/>
<div style="line-height: normal; margin-bottom: 6px; ">
Sophisticated black with detailed accent lining
</div>
<br/>
<div style="line-height: normal; margin-bottom: 6px; ">
Tailored satin ribbon release pull-strap
</div>
<br/>
<div style="line-height: normal; margin-bottom: 6px; ">
Slim back pocket for an ID card or money
</div>
<br/>
<div style="line-height: normal; margin-bottom: 6px; ">
Tailored satin ribbon release pull-strap
</div>
<br/>
.开发者_Python百科..
...
...
</div>
Can you help me a little bit.
Thanks.
Call me old fashioned but converting markup like that (esp something like <br>
to <br/>
) is something that should be done in the original file, not with jQuery after it's been sent and rendered by the browser.
I think you'll be really hard-pressed to do this without modifying the original code since you don't have spans or anything to query on.
Here is the solution I was looking for :
jQuery("div").filter(lineHeight).contents(nonElementNodes).wrap("<div style='margin-bottom:9px;line-height:normal;margin-top:4px'>");
jQuery("div").filter(lineHeight).find("br").remove();
function lineHeight() {
return this.style.lineHeight == "25px";
}
function nonElementNodes() {
return this.nodeType !== 1 || this.tagName !== 'BR';
}
Source
精彩评论