Ho HTML con diversi tag personalizzati. Voglio trovare tutti tranne due ('start', 'end') e scartarli. jQuery.find() sembra trovare solo questi tag personalizzati quando cerco cosa c'è nel documento, non quando cerco un oggetto jQuery. Che cosa sto facendo di sbagliato?jQuery non trova tag personalizzati
dovrebbe essere auto-esplicativo del violino:
Ecco la parte 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)
e un esempio di 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>
che dovrebbe be:
CTAGCTCTCTGGAGATTAACGAGGAGAAATACTAGAtTGGTTCAT<start feat="1" class="ng-scope"></start>GATCATAAgcttgaat<end feat="1" class="ng-scope"></end>tagccaaacttatt
Grazie
html con tag personalizzati non è più html –
è con l'eccezione di
Perché scrivere HTML in questo modo? Quali vantaggi ha il tag ' ' hanno più di '
' o ''? Per non parlare, è più veloce usare il selettore '$ ('. ClassName')'. – Dom