2011-12-15 38 views
2

我有一個HTML頁面,我需要在其上用一個類包裹一個額外的span標籤。獲取跨度的內部文本,並用新的跨度包裝

<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

你必須調用wrap()方法jQuery對象上:

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

http://jsfiddle.net/EkAPu/

0

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