Created
July 11, 2012 11:55
-
-
Save gawaooooo/3089920 to your computer and use it in GitHub Desktop.
【jQuery】wrapInner:各要素の子要素を、HTMLで作成した要素で囲む
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var elm = $('div.hoge'); | |
elm | |
.find('span.count').remove() | |
.end() | |
.css({'z-index': 100, | |
'position': 'absolute', | |
'left': '10px', | |
'top': '20px' | |
}) | |
.find('img') | |
.css({'border': '1px solid #fff'}) | |
.end() | |
.append('<span class="foo"><img src="bar.png"></span>') | |
.wrapInner('<div class="wrapInner"></div>') | |
.append('<span class="huga"><img src="hugahuga.png"></span>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 元のhtml --> | |
<div class="hoge"> | |
<img src="hogehoge.png"> | |
<span class="count">123</span> | |
</div> | |
<!-- js実行後のhtml --> | |
<div class="hoge" style="z-index: 1; position: absolute; left: 10px; top: 20px;"> | |
<div class="wrapInner"> | |
<img src="hogehoge.png" style="border: 1px solid #fff"> | |
<span class="foo"><img src="bar.png"></span> | |
</div> | |
<span class="huga"><img src="hugahuga.png"></span> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment