B
B
berzhikeev2018-03-07 14:40:45
JavaScript
berzhikeev, 2018-03-07 14:40:45

How to get dom element from object property?

How to get dom element from object property? To further use it as a standard dom and all its properties?

//var board =
class Ceil {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
    fullName() {
        return 'hello it x ' + this.x;
    }
    getHtml(){
        return "<div class='cell cell_white x_"+this.x+" y_"+this.y+"' id='cell_"+this.x+"_"+this.y+"'></div>";
    }
    getDomEl(){
        return  document.querySelector('#cell_'+this.x+'_'+this.y+'').outerHTML;
    }
}
var ceil_el = new Ceil(x, y);
var board = document.querySelector("#board");
board.innerHTML += ceil_el.getHtml();
dom_el = ceil_el.getDomEl();
dom_el.innerHtml = '<p>some text</p>';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton fon Faust, 2018-03-07
@berzhikeev

https://jsfiddle.net/anton4ept/018wafr7/
and do not pervert.
Read better about the DOM in general, and this one: https://developer.mozilla.org/ru/docs/DOM/document... in particular.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question