我有幾個自定義標籤的HTML。我想找到除了兩個之外的所有東西('開始','結束')並拆開它們。當我搜索文檔中的內容時,jQuery.find()似乎只能找到這些自定義標籤,而不是當我搜索jQuery對象時。我究竟做錯了什麼?jQuery不會找到自定義標籤
應該是不言自明的小提琴:
這裏的JavaScript部分:
var raw = $('pre').html();
var html = $(raw);
var starts = html.find('start');
var spans = html.find('span');
//this returns nothing
console.log(starts)
// works - can find in object
console.log(spans)
//this works
console.log($('start'));
//only picks up spans, not annotations
// I want this to return the innerHTML of the pre, stripping all tags except for 'start' and 'end' -- but retain the contents of those tags.
var cleaned = html.find(':not(start, end)').each(function() {
$(this).contents().unwrap();
});
console.log(cleaned);
$('#clean').html(cleaned)
和HTML的例子:
<span class="ng-scope">CTAGCTCTCTGGAGATTAACGAGGAGAAATACTAGAtTGGTTCAT</span>
<start feat="1" class="ng-scope"></start>
<annotation index="1" class="ng-isolate-scope ng-scope" style="background-color: rgb(238, 153, 238); background-position: initial initial; background-repeat: initial initial;">
<span tooltip="Another Promoter" tooltip-placement="mouse" tooltip-append-to-body="true" ng-transclude="" class="ng-scope">
<span class="ng-scope">GATCATAAgcttgaat</span>
</span>
</annotation>
<end feat="1" class="ng-scope"></end>
<span class="ng-scope">tagccaaacttatt</span>
即應成爲:
CTAGCTCTCTGGAGATTAACGAGGAGAAATACTAGAtTGGTTCAT<start feat="1" class="ng-scope"></start>GATCATAAgcttgaat<end feat="1" class="ng-scope"></end>tagccaaacttatt
感謝
HTML與自定義標籤不再是HTML –
與
爲什麼要用這種方式編寫HTML?標籤' '有什麼好處'
'或''?更不用說,使用選擇器'$('。className')'會更快。 – Dom