채택완료

ins 태그 내 문자열 치환?

현재

아래와 같은 태그가 한페이지에 여러번 출력 중입니다.

<ins ab-cd="12345"></ins>

<ins ab-cd="22657"></ins> 숫자는 모두 다른 상태

 

 

이 태그를

스크립트를 이용해 화면 출력시 모두 동일하게 다음과 같이 치환하려고 합니다.

<ins ef-gh="67890"></ins>

<ins ef-gh="67890"></ins> 숫자도 모두 동일하게

 

이런게 가능할까요?

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

자바스크립트 말씀이죠?

 

Copy
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<ins ab-cd="12345"></ins>
<ins ab-cd="22657"></ins>
<script>
$(function() {
    $.each($('ins[ab-cd]'), function() {
        if ($(this).attr('ab-cd').match(/^[0-9]+$/)) {
            $(this).removeAttr('ab-cd').attr('ef-gh', '67890');
        }
    });
});
</script>

답변에 대한 댓글 1개

답변을 작성하려면 로그인이 필요합니다.