0

Considering these simple html:

<html> <body> <h1 id='h1'>hello casperjs</h1> <a href='javascript: rmH1()'>remove</a> <script> function rmH1(){ document.getElementById('h1').remove(); } </script> </body> </html> 

By clicking the a element the h1 element is removed.
And next is my js code written in coffeescript:

casper = require('casper').create() casper.start 'file:///Users/username/my.html', -> @capture 'before.png' @evaluate -> rmH1() @capture 'after.png' casper.run() 

However from the screenshots the h1 element was not removed as well.
How do I correctly call the remote function rmH1()?

1
  • 2
    not duplicate, but might provide some insight: CasperJS evaluate Commented Jun 29, 2015 at 7:43

1 Answer 1

1

There is no such thing as element.remove(). You should use

var h1 = document.getElementById('h1'); h1.parentNode.removeChild(h1); 

Had you listened to the "page.error" event, you would have seen that remove is not a function.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.