Mam HTML z kilkoma niestandardowymi tagami. Chcę znaleźć wszystkie oprócz dwóch ("start", "koniec") i odwijaj je. jQuery.find() wydaje się znajdować tylko te niestandardowe znaczniki, kiedy przeszukuję to, co jest w dokumencie, a nie kiedy przeszukuję obiekt jQuery. Co ja robię źle?jQuery nie znajdzie niestandardowych tagów
Powinno być oczywiste na skrzypcach:
Oto część 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)
i przykładem 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>
który powinien być:
CTAGCTCTCTGGAGATTAACGAGGAGAAATACTAGAtTGGTTCAT<start feat="1" class="ng-scope"></start>GATCATAAgcttgaat<end feat="1" class="ng-scope"></end>tagccaaacttatt
Dzięki
html z niestandardowych znaczników html –
nie jest z wyjątkiem
Po co pisać HTML w ten sposób? Jakie korzyści ma tag ' ' mieć ponad '
' lub ''? Nie wspominając, że szybciej jest użyć selektora '$ ('. ClassName')'. – Dom