6

First of all I am new to imacros,I am trying to remove an element from a page using imacro in a random site, for which i have tried to use the javascript which throws me an error of .remove() is not a function. Following is the piece of code which i have been trying:

var macro = "";
macro +="SET !DATASOURCE mobidomains2.csv";
macro +="SET !DATASOURCE_COLUMNS 1";
macro ="SAVEAS TYPE=PNG FOLDER=* FILE={{!COL1}}";
window.content.document.getElementsByClassName("results-explained").remove();
var ret="";
ret=iimPlay(macro);

I have also tried it with using .removechild(), so is there any way that I can delete a specific div using imacro with javascript? Thanking you in advance.

A1rPun
  • 16,287
  • 7
  • 57
  • 90
Omkar Somji
  • 217
  • 1
  • 7

1 Answers1

3

getElementsByClassName returns a HTMLCollection. You should iterate through the set and then call the remove method on each element. Also note ChildNode.remove method is not widely-supported.

var collection = window.content.document.getElementsByClassName("results-explained");

Array.prototype.forEach.call(collection, function(node) {
    node.parentNode.removeChild(node);
});
Ram
  • 143,282
  • 16
  • 168
  • 197