dom - Remove all elements before a specified ID attribute using pure javascript -
i'm using web service query ticketing interface , pull support tickets open @ point in time, displaying them in nice neat table within iframe part of our web application. application written in pl/sql use construct html pages , content displayed within iframe. main issue because tickets made of email content, there lot of useless rubbish (mostly tags) , irrelevant text included @ top of email content causes interface trashy.
within code wrapping main areas of content require in table id of "ticketstable" , remove elements or content within iframe occurs before tickets table.
usually use jquery task:
$("#earliercontent").nextuntil("#ticketstable").andself().remove();
however, our system built using extjs wish avoid potential conflict jquery library cause environment. therefore need way process , loop through contents of iframe, removing elements , text occur before tickettable id therefore eradicating of unnecessary content.
i've tried this:
var last = null; var curr = $('#page1'); while (curr.attr('id') != 'ticketstable') { if (last != null) { last.remove(); } last = curr; curr = curr.next(); } if (last != null) { last.remove(); }
source: jquery remove elements until id='whatever' found
however, email content variable, there no specific id tag can specify script start at. therefore, there alternative method can use (without library, pure javascript) remove elements , content before ticketstable?
i must stress contents of ticketstable must remain intact. content occur before within body wish remove.
var parent = document.getelementbyid("parent"); var stopid = "stop"; var length = parent.childnodes.length, j = 0; for(var i=0; < length; i++){ if(parent.childnodes[j].id != stopid){ parent.removechild(parent.childnodes[j]); } else{ j++; } }
when remove child node, array shifted, if example need remove 2 first nodes, call removechild index 0 2 times.
Comments
Post a Comment