제이쿼리 replace 질문 채택완료
<div id="hello">
<table>
<thead>
<tr>
<td>ab a</td>
<td>b a a</td>
<td>caa</td>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</tbody>
</table>
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</div>
#hello 안에 있는 모든 a 를 b 로 바꾸고 싶습니다.. 도움부탁드립니다
답변 1개
채택된 답변
+20 포인트
8년 전
$('#hello td, #hello li').each( function() {
$(this).text( $(this).text().replace(/a/g, 'b') );
})
로그인 후 평가할 수 있습니다
답변에 대한 댓글 2개
8년 전
8년 전
// 정규식은 구문을 보고 패턴을 만드는 것이기 때문에 아래 코드는 참고만 하세요
$('#hello').find('*').each( function() {
$(this).html( $(this).html().replace(/a/g, 'b') );
})
$('#hello').find('*').each( function() {
$(this).html( $(this).html().replace(/a/g, 'b') );
})
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
$(#hello).find().each(function() { 로 해보니 find에 자식을 정해줘야 실행이됩니다