Class: Constructor

ko/dom~ Constructor


Constructor()

These methods live on the exported function, you can access them like so:

require("ko/dom").methodName(..)

Methods


<static> create(selector, attributes, content)

Quickly create DOM structure Based on: http://gist.github.com/278016

Example usage:

    $.create('A href=#' , {class: "foo"}, $.create('IMG src="http://bit.ly/WinAylott"')
   ('BR')
   ('' ,"View larger image") )
Parameters:
Name Type Description
selector string

The element definition

attributes object | string | undefined

Attributes to add to the element, if content is undefined and this is a string then the value of attributes will be used as the content param

content string | undefined

Content to append

Author:
  • Thomas Aylott (original author)
License:
  • MIT
Returns:

Returns instance of this function, so you can chain calls

Type
module:ko/dom~Constructor.create

<static> createElement(html, allowMultiple)

Create element from complex string input

Parameters:
Name Type Description
html String

HTML string, must validate properly (no syntax errors), can also be just the nodename

allowMultiple Bool | Object

boolean or object, if object then this is taken as an object of attributes to assign to the element

Returns:
Type
Node

<static> escape(str)

Escape given string (html entities encode)

Parameters:
Name Type Description
str String

The input string

Returns:
Type
String

<static> window(w)

Get a ko/dom instance for the given window

Example
var $ = require("ko/dom").window(myWindow);
$(".foo").text("bar");
Parameters:
Name Type Description
w Window

Window reference

Returns:

Returns a ko/dom instance for the given window

Type
module:ko/dom