Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Automatic node finding


Like jQuery with its $ function, Polymer also has a very handy way to locate nodes in the DOM of the page. This recipe shows you how to use it. You can find the code in the project find_nodes.

How to do it...

  1. The script starts with web\index.html, where a component with the name find-nodes is imported through the following line:

    <link rel="import"href="find_nodes.html">

    From this, we know that the component is defined in find_nodes.html, and the code behind it is in a file named find_nodes.dart. For a discussion of the other tags, refer to the first recipe.

  2. The code for find-nodes is defined in find_nodes.dart:

    import'dart.html';
    import'package:polymer/polymer.dart';
    
    @CustomTag('find-nodes')
    classFindnodes extends PolymerElement {
      Findnodes.created() : super.created();
      
      btnclick(MouseEvent  e, var detail, Node target) {
        // making the paragraph visible:
        $['show'].style
        ..display = 'inline'
        ..color = 'red';
        // changing the text inside the div...