 			
 			# Iterate all the children (templates)
 			for template in templateContainerHTML.children
+				# If no data-template attribute exists skip this element.
+				continue unless template.hasAttribute('data-template')
 				# Get the name.
 				name = template.getAttribute('data-template')
-				# If it wasn't provided it's not a template; skip.
-				continue unless name
 				# Remove the data-template attribute.
 				template.removeAttribute('data-template')
 				# Save the HTML in @templates.
 				@templates[name] = template.outerHTML
 
 	constructor: (el = null, @options = null, @owner) ->
-		if @template and (not el or el.children().length is 0)
+		if @template and (not el or el.children.length is 0)
 			@_loadTemplate()
 			if (el)
 				classes = el.attr('class')
-				if classes then @el.addClass(classes)
-				el.replaceWith(@el)
+				if classes then @el.classList.add(classes.split(' '))
+				el.parentNode.replaceChild(@el, el)
 		else
 			@el = el
 

	@views = {}

	@actionPattern = ///^(.*?):(.*?)\((.*?)\)///

	@parseTemplates: ->
		
		# Define templates
		@templates = {}

		@updateDomFromOutlet(name)
		@

	appendTo: (view) ->
		(view.el or view).appendChild(@el)
		@

	insertBefore: (view) ->
		el = view.el or view
		el.parentNode.insertBefore(@el, el)
		@
		
	insertAfter: (view) ->
		@insertBefore((view.el or view).nextSibling)
		@
		
	retract: ->
		parentNode = @el.parentNode
		nextSibling = @el.nextSibling
		@el.parentNode.removeChild(@el)
		
		return ->
			if nextSibling
				parentNode.insertBefore(@el, nextSibling)
			else
				parentNode.appendChild(@el)
		
	remove: ->
		@el.parentNode.removeChild(@el)
		@

	addClass: (names...) ->
		@el.classList.add.apply(@el.classList, names)
		@

	removeClass: (names...) ->
		@el.classList.remove.apply(@el.classList, names)
		@
	
	toggleClass: (name, addOrRemove) ->
		@el.classList.toggle(name, addOrRemove)
			
	hasClass: (name) ->
		@el.classList.contains(name)

	enable: (recursive = true, updateClass = true)->
		@enabled = true
