2011-12-15 18 views
2

私はいくつかのHTMLを持つページを持っています。追加のスパンタグをクラスでラップする必要があります。スパンの内部テキストを取得し、クラスを使用して新しいスパンでラップします

<span class="VIEWBOX" id="_Datacomp_c_importantnote"> 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. vestibulum vel tellus. Morbi suscipit enim ac <BR> 
</span> 

親スパンにあるクラス/ IDは使用できません。新しいスパースを作成する必要があります。

私は

var innnerNoteText = $('#_Datacomp_c_importantnote').text(); 
innerNoteText.wrap('<span class="noteText"></span>'); 

を書かれている。しかし、これは動作していない、任意のヘルプは素晴らしいだろう!

答えて

0

文字列を返します$('...').text()、何の方法wrapはありません。

あなたはjQueryオブジェクトにwrap()メソッドを呼び出す必要があります:

$('#_Datacomp_c_importantnote').wrap('<span class="noteText"></span>'); 

http://jsfiddle.net/EkAPu/

0

$('#_Datacomp_c_importantnote').html('<span class="noteText">' + $(this).text() + '</span>');

関連する問題