3gwebtrain
3gwebtrain

Reputation: 15293

How to get a children element from object

I am getting data from backend, once that is applied to template using my template function like this :

this.render = function() {
        var html = Mustache.render(self.template.base.html());

        self.el.parent.html(html);
        self.el.panel = $('.header-panel', self.el.parent);

        console.log ( self.el.panel );

    };

My "self.el.panel" (consoled) giving me the result like this:

  0: div.header-panel.flex-right
    context: document
    length: 1
    prevObject: jQuery.fn.jQuery.init[1]
    selector: "#header .header-panel"

From this data, how can i find a child elements?

I tried like this, but no luck..

console.log ( $("a", self.el.panel) );

even like this:

console.log ( $(self.el.panel).find('a') );

any one help me to get the child elements..

Upvotes: 2

Views: 230

Answers (1)

Tomalak
Tomalak

Reputation: 338158

According to your code sample, self.el.panel is a jQuery object.

Therefore...

self.el.panel = $('.header-panel', self.el.parent);

// ...

var childA = self.el.panel.children("a");
var descendantA = self.el.panel.find("a");

If that does not give you anything, then there are no <a> elements in that section (or not at that time).

Upvotes: 1

Related Questions