Comparing version 3.4.0 to 3.4.1
@@ -318,2 +318,3 @@ (function (document) { | ||
* @returns {Element} | ||
* @deprecated Use querySelector instead of. | ||
*/ | ||
@@ -350,6 +351,12 @@ Monkberry.View.prototype.getElementById = function (id) { | ||
var element = this.nodes[i].querySelector(query); | ||
if (element) { | ||
return element; | ||
if (this.nodes[i].nodeType === 8) { | ||
throw 'Can not use querySelector with non-element nodes on first level.'; | ||
} | ||
if (this.nodes[i].querySelector) { | ||
var element = this.nodes[i].querySelector(query); | ||
if (element) { | ||
return element; | ||
} | ||
} | ||
} | ||
@@ -356,0 +363,0 @@ return null; |
{ | ||
"name": "monkberry", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "JavaScript DOM Template Engine", | ||
@@ -5,0 +5,0 @@ "bin": "bin/monkberry", |
@@ -42,2 +42,3 @@ # Monkberry - JavaScript template engine | ||
- [Parsers](#parsers) | ||
- [Unsafe](#unsafe) | ||
- [Comments](#comments) | ||
@@ -610,8 +611,2 @@ - [API Reference](#api-reference) | ||
#### view.getElementById(id) | ||
Get element by id. | ||
* `id`: `string` - id of element. | ||
#### view.querySelector(query) | ||
@@ -625,3 +620,20 @@ | ||
> Note what querySelector can not work with template which have if/for/custom node on first level. | ||
> ```twig | ||
> {% if cond %} | ||
> ... | ||
> {% endif %} | ||
> ``` | ||
> You will got exception like this: `Can not use querySelector with non-element nodes on first level.` | ||
> | ||
> Solution is to wrap such statement into another node: | ||
> ```twig | ||
> <div> | ||
> {% if cond %} | ||
> ... | ||
> {% endif %} | ||
> </div> | ||
> ``` | ||
## Tests | ||
@@ -628,0 +640,0 @@ |
97238
2051
650