Javascript - remove / node element without id and specific content

I am trying to decipher a way to remove several specific href elements that do not contain identifiers and are children of individual parents without identifiers.

The best I can decide is to identify four offensive, out of 8 or 9 href tags (and the number may vary) by a specific word inside the URL itself. To do this, I do the following:

<script language=javascript>
var xx = document.getElementById('theID').getElementsByTagName('a');
var ptn=/\=media/;
for(var i=0; i<xx.length; i++) {
    if(ptn.exec(xx[i])){
    alert(xx[i]);
    }
}
</script>

Of course, all this gives me four specific URLs inside href where "= media" is present. Now, somehow, I need to be able to remove either these href elements or their parent elements (which, as it happens, are unordered list tags). This is not until I get a higher level (table cell) to access the identifier of the element or something different from the specific word inside the URL itself.

I am open to any approach at the moment - PHP may be an option (I have not studied it yet), but for this javascript was my first logical choice. I can’t interfere with the page that directly creates the links, but only the secondary page, which is turned on at the time the page loads.

Any pointers on how to solve this problem?

============================== ============================================================

<script language=javascript>
var xx = document.getElementById('theID').getElementsByTagName('a');
var ptn=/\=media/;
for(var i=0; i<xx.length; i++) {
    while(ptn.exec(xx[i].href)){
        alert(xx[i]);
        xx[i].parentNode.removeChild(xx[i]);
    }
}
</script>
+3
3

, . ( ).

:

alert(xx[i]);

:

XX[i].parentElement.removeChild(xx[i]);
+1

removeChild() , :

xx[i].parentNode.removeChild(xx[i]);

href. if :

if(ptn.exec(xx[i].href)){
+1
var parent = xx[i].parentNode;
parent.removeChild(xx[i]);

http://www.onlinetools.org/articles/unobtrusivejavascript/chapter2.html ( ).

0

Source: https://habr.com/ru/post/1769638/


All Articles