2011-12-15 40 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>');