1

I am thinking how KnockoutJs or AngulasJs type of frameworks allow us to add new Attributes, Elements etc in our HTML Code? How does the compiler at runtime allows these frameworks.

The only thing I can think of is that these frameworks have their custom DTD loading on the HTML page, but I can't see any reference to any DTD in html code. Any suggestion how should I proceed?

Gaurav Sharma
  • 586
  • 3
  • 10
  • 5
    custom attributes are valid in HTML5. ` `. Otherwise, if not using html5 doctype, you can use `data-ng-model` instead of `ng-model` – Kevin B Mar 18 '15 at 20:42

1 Answers1

0

As Kevin notes, custom attributes are legal in HTML5 if they start with -data.

You can put attributes that do not start with -data on an element, and modern browsers will not care, even though they are not valid per-spec. They will not have any effects, but they will not be removed. Javascript can then identify nodes that have them, and add behavior however they need to.

Custom Elements are also legal in modern browsers. In older version of Internet Explorer they can be defined using document.createElement. Knockout uses this method.

Community
  • 1
  • 1
Kyeotic
  • 19,697
  • 10
  • 71
  • 128