jQuery를 사용하여 쉼표 뒤에 스팬을 삽입 할 수 있기를 원합니다. JQuery를 사용하여 쉼표 뒤에 div에 스팬 삽입
<div class="title">Some text,<span class="something"> with a comma.</span></div>
는 HTML 쉼표 후에 만 대상 또는 텍스트를 추가 할 수있는 방법이 있나요 :
내가 그들 모두를 만들고 싶어
<div class="title">Some text, with a comma.</div>
<div class="title">Some text, with a comma.</div>
<div class="title">Some text, with a comma.</div>
<div class="title">Some text, with a comma.</div>
<div class="title">Some text, with a comma.</div>
<div class="title">Some text, with a comma.</div>
는 다음과 같이 : I는 다음과 같이 된 div의 번호를 가지고 제목의 종류?
$(".title").html(function (index, html) {
var commaIndex = html.indexOf(",");
var beginningHtml = html.substring(0, commaIndex + 1);
var endingHtml = html.substring(commaIndex + 1);
return beginningHtml + "<span class=\"something\">" + endingHtml + "<\/span>";
});
여기 내 코드에 대한 a jsFiddle입니다 :
당신은 무엇을 시도? 문제를 해결하기 위해 만든 코드를 게시하십시오. –
쉼표가 두 개 이상이면 어떨까요? 새 요소를 각 인스턴스에 대해 복제해야합니까, 아니면 처음, 마지막 또는 다른 인스턴스에 삽입해야합니까? 또한 엄밀히 말하면 질문에 대한 대답은 '예'입니다. 더 긴 대답은 당신이 원하는 것, 당신이 가질 수있는 제약과 요구 사항에 달려 있다는 것입니다. –
Okay guys .... 이걸 망각으로 downvoting하기 전에 몇 분 정도 줘. – gan