split 후 공백 제거하기 채택완료
안녕하세요!
js로 해당 가게 주소를 불러온 후 주소 중 || 뒤에 있는 전화번호를 split로 분리 했습니다!
그런데 불러온 내용 안에 이미지가 들어있어서 ' & nbsp '; 로 인한 공백이 계쏙 생깁니다ㅠㅠ
split로 주소와 전화번호를 분리 한 후, 전화번호 뒤에 있는 공백을 어떻게 삭제해야 하나요?

$(".store_cont").each(function(){ var conTxt = $(this).text(); var arr = conTxt.split("||");
var addr = arr[0]; var tel = arr[1];
$(this).html(addr).show(); $(this).parent().parent().find('.store_tel').html(tel); });
답변 2개
채택된 답변
+20 포인트
3년 전
if 추가해보세요
if(tel) tel= tel.replace(/ /gi,""); //공백제
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
�
3년 전
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
�
3년 전
답변 감사합니다!! 아래처럼 추가하면 되나요?
추가했더니 에러가 뜹니다!ㅠㅠ
$(".store_cont").each(function(){
var conTxt = $(this).text();
var arr = conTxt.split("||");
var addr = arr[0];
var tel = arr[1];
tel= tel.replace(/ /gi,""); //공백제거
$(this).html(addr).show();
$(this).parent().parent().find('.store_tel').html(tel);
});
Uncaught TypeError: Cannot read properties of undefined (reading 'replace')
추가했더니 에러가 뜹니다!ㅠㅠ
$(".store_cont").each(function(){
var conTxt = $(this).text();
var arr = conTxt.split("||");
var addr = arr[0];
var tel = arr[1];
tel= tel.replace(/ /gi,""); //공백제거
$(this).html(addr).show();
$(this).parent().parent().find('.store_tel').html(tel);
});
Uncaught TypeError: Cannot read properties of undefined (reading 'replace')
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인전체 질문 목록
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
채택
답변대기
답변대기
답변대기
이렇게 넣으니까 공백 사라졌습니다!! 감사합니다!!