Removing a div element using coffeescript

I want to remove an element divwith a specific attribute classusing Coffeescript. I could not find any examples about manipulating the DOM with Coffeescript on the Internet. How can i do this? Also, any links to running the DOM would be great.

+3
source share
2 answers

CoffeeScript is a JavaScript preprocessor; there is no additional standard library. This means that if you want to manipulate the DOM, you will do it the same way as in JavaScript.

You can use any JavaScript library, such as jQuery with CoffeeScript, as an alternative, you can directly use the variable document:

element.parentNode.removeChild(element) for element in document.getElementsByClassName('some-class')

( , )

element.parentNode.removeChild(element) for element in document.getElementsByTagName('*') when element.className = 'some-class'

, , :

for element in document.getElementsByTagName('*')
    if element.className is 'some-class'
        element.parentNode.removeChild(element)

CoffeeScript.org:

CoffeeScript: " JavaScript". -- JS, . JavaScript CoffeeScript ( ).

+5

@lauren , , : Uncaught TypeError: 'id' undefined

, Chrome.

$(document).on 'hidden.bs.modal', "#newProject", ->
  document.getElementById("<ID>").outerHTML=''
  delete element

: fooobar.com/questions/11869/...

0

All Articles